Skip to content

Instantly share code, notes, and snippets.

@brock
Created July 17, 2014 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brock/e0fdc05bd8d49fc234c7 to your computer and use it in GitHub Desktop.
Save brock/e0fdc05bd8d49fc234c7 to your computer and use it in GitHub Desktop.
GROOT - go to the "git root"
#!/bin/bash
# GROOT! v 1.0.0
# Install in your dotfiles, .bashrc, .zshrc or similar
# No more cd ../../../../.. to get to the root of a git project
# Running the command "groot" will look for the closest .git directory and take you there.
# Note that it doesn't traverse up the tree, it takes you directly to the directory with a .git in it...
# ...so the command `cd -` takes you back to where you were.
# Works with *some* submodules (depending on how your submodule was setup - as a file or a dir)
# If you are using submodules, you should be able to figure out how to modify this.
# If you are using submodules, but you CAN'T figure out how to modify this, go here: http://goo.gl/nI0zLc
function groot() {
GROOTDIR=$PWD
FOUND=$(find $GROOTDIR -type d -name ".git")
while [ -z "$FOUND" ]
do
GROOTDIR=$(dirname $GROOTDIR)
FOUND=$(find $GROOTDIR -type d -name ".git")
done
cd $GROOTDIR
unset GROOTDIR
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment