27 03 2015
“git root” – root folder of the git repository
How often do you wanted to go to the root of the git repository? If not very often, then I do it quite often.
Mercurial has this nice command hg root
, but git not. In order to do it in git you have to use some long command 'rev-parse --show-toplevel'
which I even can’t remember. Fortunately git has aliases which can be used to define custom commands, like git root
:
git config --global alias.root 'rev-parse --show-toplevel'
Now, if I want to go to the root of the project, only what I have to do is to type in bash:
cd $(git root)
Using = null; instead of ; NPM, tmp and npm-xxx uncleaned paths
Another option is to create a !pwd alias, since aliases are executed from the repo root.
git config –global alias.root ‘!pwd’