Notes of Maks Nemisj

Experiments with JavaScript

“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)


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.