Created
February 11, 2022 22:52
-
-
Save timmc-edx/786dc5429d6c60e4344e6b83d2aab638 to your computer and use it in GitHub Desktop.
Aliases for fetch or pulling the git default branch
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
function git_default_branch { | |
# Guess the name of the remote -- either origin or the first other remote | |
guessed_remote="$( | |
( | |
git remote | grep -P '^origin$' | |
git remote | grep -P '^origin$' -v | |
) | head -n1 | tr -d '\n' | |
)" | |
git symbolic-ref "refs/remotes/$guessed_remote/HEAD" \ | |
| sed 's|^refs/remotes/[^/]\+/||' | |
} | |
alias gpm="git checkout \$(git_default_branch) && git pull" | |
alias gfm="git fetch origin && git branch -f \$(git_default_branch) origin/\$(git_default_branch)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment