13 April 2021

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.


Previous post
Showing A File At A Specific Git Revision Here is a technique for showing the version of a file at a specific Git revision. It’s not a novel technique — there’s naturally a Stack Overflow
Next post
No More Link Posts to Tools or Packages For a brief period of time, when coming across a package or tool that I wanted to make a note of, I added it to this blog in the form of a link