Skip to content

Instantly share code, notes, and snippets.

@Emille1723
Forked from brettinternet/check-git-2.sh
Created May 20, 2025 13:58
Show Gist options
  • Save Emille1723/2a5801677429031ad06543100777a22d to your computer and use it in GitHub Desktop.
Save Emille1723/2a5801677429031ad06543100777a22d to your computer and use it in GitHub Desktop.
Check if directory is a git repo or not
# from https://stackoverflow.com/questions/2180270/check-if-current-directory-is-a-git-repository
[ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1
# Copyright (C) 2006,2007 Shawn O. Pearce <[email protected]>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
if [ -d .git ]; then
echo .git;
else
git rev-parse --git-dir 2> /dev/null;
fi;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment