git-root

I wrote a little bash alias a while ago to help me instantly to the root directory of a git project from any directory beneath it.

It’s pretty simple. Assume /projects/foo is the root of a project under git. Assume your pwd is /projects/foo/bar/baz. At the prompt, typing git-root will return you to /projects/foo.

This works by changing pwd to be the actual .git directory under the project root, and then backing out of it one level up (to ..).

2 thoughts on “git-root

Leave a Reply

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