4 ms·
I use this alias to quickly cd to the root directory of a repo. Useful if you're way deep in a repo and need to back out. alias gitroot='cd $(git rev-parse
by theden 9y ago
I use this alias to quickly cd to the root directory of a repo. Useful if you're way deep in a repo and need to back out.
alias gitroot='cd $(git rev-parse --show-toplevel) && echo "$_"'
- mythrwy 9y agoborrowed and my fingers thank you!
- mort96 9y agoYou might also be interested in this function from my zshrc: https://github.com/mortie/nixConf/blob/f078de8890461d247af459cc966a15449c9515e7/.shrc#L40 https://github.com/mortie/nixConf/blob/f078de8890461d247af45... Basically, if you're in the directory `~/something/src/projectname/foo/com/something/bar/baz`, and want to get back up to say `~/something/src/projectname/foo`, `to foo` will do that. (Or `to oo` or `to o`; it matches the end of the name, and goes to the first match; `to ing` would go to `~/something/src/projectname/foo/com/something`).
- ioltas 9y agoYou can enforce a portion of that directly in your .gitconfig: [alias] # Show top level repository root = rev-parse --show-toplevel I have found that useful over time.