public
Last active

git-root script that prints the root of a git repository

  • Download Gist
git-root
Shell
1 2 3 4 5 6 7 8 9 10 11 12
#!/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
)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.