Jumping to the Root of a Git Repo
Sometimes, when you’re browsing your social feeds, you come across a tool or technique for doing something that you think is good to know, but you have no immediate use for it. Then a couple of hours later, while working on something else, you find yourself needing that exact bit of information.
This occurred to me this morning. While getting coffee, I saw someone post a tweet documenting a way to get to the root directory of a Git repo. Could be useful, I thought. Then, while writing a script to prep a Pull Request, I found myself needing to do exactly this.
Here is the command to jump to the root of a Git repo:
$ cd $(git rev-parse --show-toplevel)
Truly a Serendipitous Event.