Create a gist now

Instantly share code, notes, and snippets.

@jdsumsion /git-root
Last active Dec 21, 2015

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