Have git check out main branch if present (#1886)

Create function to get default git branch, and use main branch if present
pull/1901/head
Zhengnan Zhao 2021-06-23 06:26:48 -04:00 committed by GitHub
parent e51fe1fe2b
commit 0f3e4dc8be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 9 deletions

View File

@ -37,8 +37,8 @@ alias gcb='git checkout -b'
alias gco='git checkout' alias gco='git checkout'
alias gcob='git checkout -b' alias gcob='git checkout -b'
alias gcobu='git checkout -b ${USER}/' alias gcobu='git checkout -b ${USER}/'
alias gcom='git checkout master' alias gcom='git checkout $(get_default_branch)'
alias gcpd='git checkout master; git pull; git branch -D' alias gcpd='git checkout $(get_default_branch); git pull; git branch -D'
alias gct='git checkout --track' alias gct='git checkout --track'
# clone # clone
@ -64,7 +64,7 @@ alias gf='git fetch --all --prune'
alias gft='git fetch --all --prune --tags' alias gft='git fetch --all --prune --tags'
alias gftv='git fetch --all --prune --tags --verbose' alias gftv='git fetch --all --prune --tags --verbose'
alias gfv='git fetch --all --prune --verbose' alias gfv='git fetch --all --prune --verbose'
alias gmu='git fetch origin -v; git fetch upstream -v; git merge upstream/master' alias gmu='git fetch origin -v; git fetch upstream -v; git merge upstream/$(get_default_branch)'
alias gup='git fetch && git rebase' alias gup='git fetch && git rebase'
# log # log
@ -104,7 +104,7 @@ alias gp='git push'
alias gpd='git push --delete' alias gpd='git push --delete'
alias gpf='git push --force' alias gpf='git push --force'
alias gpo='git push origin HEAD' alias gpo='git push origin HEAD'
alias gpom='git push origin master' alias gpom='git push origin $(get_default_branch)'
alias gpu='git push --set-upstream' alias gpu='git push --set-upstream'
alias gpunch='git push --force-with-lease' alias gpunch='git push --force-with-lease'
alias gpuo='git push --set-upstream origin' alias gpuo='git push --set-upstream origin'
@ -112,7 +112,7 @@ alias gpuoc='git push --set-upstream origin $(git symbolic-ref --short HEAD)'
# pull # pull
alias gl='git pull' alias gl='git pull'
alias glum='git pull upstream master' alias glum='git pull upstream $(get_default_branch)'
alias gpl='git pull' alias gpl='git pull'
alias gpp='git pull && git push' alias gpp='git pull && git push'
alias gpr='git pull --rebase' alias gpr='git pull --rebase'
@ -128,9 +128,9 @@ alias grm='git rm'
# rebase # rebase
alias grb='git rebase' alias grb='git rebase'
alias grbc='git rebase --continue' alias grbc='git rebase --continue'
alias grm='git rebase master' alias grm='git rebase $(get_default_branch)'
alias grmi='git rebase master -i' alias grmi='git rebase $(get_default_branch) -i'
alias gprom='git fetch origin master && git rebase origin/master && git update-ref refs/heads/master origin/master' # Rebase with latest remote master alias gprom='git fetch origin $(get_default_branch) && git rebase origin/$(get_default_branch) && git update-ref refs/heads/$(get_default_branch) origin/$(get_default_branch)' # Rebase with latest remote
# reset # reset
alias gus='git reset HEAD' alias gus='git reset HEAD'
@ -174,7 +174,7 @@ alias gsu='git submodule update --init --recursive'
# these aliases requires git v2.23+ # these aliases requires git v2.23+
alias gsw='git switch' alias gsw='git switch'
alias gswc='git switch --create' alias gswc='git switch --create'
alias gswm='git switch master' alias gswm='git switch $(get_default_branch)'
alias gswt='git switch --track' alias gswt='git switch --track'
# tag # tag
@ -196,3 +196,11 @@ esac
function gdv() { function gdv() {
git diff --ignore-all-space "$@" | vim -R - git diff --ignore-all-space "$@" | vim -R -
} }
function get_default_branch() {
if git branch | grep -q main; then
echo main
else
echo master
fi
}