Hacks

gitroot – a Simple Command to Navigate to the Root of a Git Repo

When it comes development environments I’m old fashioned – I prefer using Vim and navigate the filesystem from the terminal.

A thing that always annoyed me is returning to top level directory in a git repo from somewhere deeper within.

It turns out that there’s a really simple solution – just make a bash alias gitroot as follows

alias gitroot='cd $(git rev-parse --show-toplevel)'

Put that line either in ~/.bashrc or if you use zsh in ~/.zshrc and you’re all set. Whenever inside a git repo, typing gitroot will take you to its root dir.