Skip to content

Instantly share code, notes, and snippets.

@jdsumsion
Last active December 21, 2015 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdsumsion/6282953 to your computer and use it in GitHub Desktop.
Save jdsumsion/6282953 to your computer and use it in GitHub Desktop.
git-root script that prints the root of a git repository
#!/bin/bash
GIT_DIR=`git rev-parse --git-dir` &&
(
if [ `basename $GIT_DIR` = ".git" ]; then
# handle normal git repos (with a .git dir)
cd $GIT_DIR/..
else
# handle bare git repos (the repo IS a xxx.git dir)
cd $GIT_DIR
fi
pwd
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment