Skip to content

Instantly share code, notes, and snippets.

@funkyfisch
Last active February 17, 2023 11:54
Show Gist options
  • Save funkyfisch/4dedefc00bb9ad724cc6f623b410e514 to your computer and use it in GitHub Desktop.
Save funkyfisch/4dedefc00bb9ad724cc6f623b410e514 to your computer and use it in GitHub Desktop.
Git navigation

Commands

cd $(git rev-parse --show-toplevel) # navigates to the root directory of a repo/submodule.
cd $(git rev-parse --git-dir) # navigates to the .git directory.
cd $(git rev-parse --show-superproject-working-tree) # if in a submodule, navigates to the root of the parent.

Aliases

# given a remote branch (for a PR or MR) check it out locally and track it
git config --global alias.new-from-remote '!f() { git checkout -b "$1" "origin/$1"; }; f'
# given a remote branch (for a PR or MR) check it out locally and track it
git config --global alias.new-from-remote '!f() { param($branch); git checkout -b $branch origin/$branch; }; f'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment