When working in git repositories, you (read: I) often want to go back to the repository top level directory, and used to do something like
But found out that you with
git rev-parse can add the parameter
--show-cdup which tells you
the path to the top level directory of the repository relative to the current
git rev-parse --show-cdup
With git version 1.7.0+ you can use
--show-toplevel which shows the absolute
path to the top level directory of the repository.
git rev-parse --show-toplevel
So in my shell (bash or zsh) i have made an alias to easy cd into this directory, so edit and add this line to your .zshrc .bashrc or whatever
alias gitroot='cd $(git rev-parse --show-toplevel)'
And restart your shell, and cd into a git repository, and do a
back to top level directory.