Created
September 7, 2023 18:34
-
-
Save qpwo/7e07f2fa881c02b77461d7c3d361ce35 to your computer and use it in GitHub Desktop.
zsh/bash alias to cd into git repo root
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# append to .zshrc or .bashrc | |
# cd into git root | |
function gr() { | |
# check in git repo: | |
if ! git rev-parse --is-inside-work-tree &>/dev/null; then | |
echo "not in git repo" | |
return 1 | |
fi | |
rel=$(realpath --relative-to=$(pwd) $(git rev-parse --show-toplevel)) | |
if [[ $rel == "." ]]; then | |
echo "already in root" | |
return 0 | |
fi | |
echo "cd $rel # $(git rev-parse --show-toplevel)" | |
cd $(git rev-parse --show-toplevel) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment