git: change main branch naming scheme (#9049)

Co-authored-by: Marc Cornellà <marc.cornella@live.com>
This commit is contained in:
Adam Vandover 2020-07-03 13:03:04 -04:00 committed by GitHub
parent 62648d71bb
commit 3178334a2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 21 deletions

View file

@ -23,7 +23,7 @@ plugins=(... git)
| gb | git branch | | gb | git branch |
| gba | git branch -a | | gba | git branch -a |
| gbd | git branch -d | | gbd | git branch -d |
| gbda | git branch --no-color --merged \| command grep -vE "^(\+\|\*\|\s*(master\|development\|develop\|devel\|dev)\s*$)" \| command xargs -n 1 git branch -d | | gbda | git branch --no-color --merged \| command grep -vE "^(\+\|\*\|\s*($(git_main_branch)\|development\|develop\|devel\|dev)\s*$)" \| command xargs -n 1 git branch -d |
| gbD | git branch -D | | gbD | git branch -D |
| gbl | git blame -b -w | | gbl | git blame -b -w |
| gbnm | git branch --no-merged | | gbnm | git branch --no-merged |
@ -47,7 +47,7 @@ plugins=(... git)
| gcl | git clone --recurse-submodules | | gcl | git clone --recurse-submodules |
| gclean | git clean -id | | gclean | git clean -id |
| gpristine | git reset --hard && git clean -dffx | | gpristine | git reset --hard && git clean -dffx |
| gcm | git checkout master | | gcm | git checkout $(git_main_branch) |
| gcd | git checkout develop | | gcd | git checkout develop |
| gcmsg | git commit -m | | gcmsg | git commit -m |
| gco | git checkout | | gco | git checkout |
@ -85,7 +85,7 @@ plugins=(... git)
| ghh | git help | | ghh | git help |
| gignore | git update-index --assume-unchanged | | gignore | git update-index --assume-unchanged |
| gignored | git ls-files -v \| grep "^[[:lower:]]" | | gignored | git ls-files -v \| grep "^[[:lower:]]" |
| git-svn-dcommit-push | git svn dcommit && git push github master:svntrunk | | git-svn-dcommit-push | git svn dcommit && git push github $(git_main_branch):svntrunk |
| gk | gitk --all --branches | | gk | gitk --all --branches |
| gke | gitk --all $(git log -g --pretty=%h) | | gke | gitk --all $(git log -g --pretty=%h) |
| gl | git pull | | gl | git pull |
@ -102,12 +102,12 @@ plugins=(... git)
| glola | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --all | | glola | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --all |
| glog | git log --oneline --decorate --graph | | glog | git log --oneline --decorate --graph |
| gloga | git log --oneline --decorate --graph --all | | gloga | git log --oneline --decorate --graph --all |
| glp | git log --pretty=\<format\> | | glp | git log --pretty=\<format\> |
| gm | git merge | | gm | git merge |
| gmom | git merge origin/master | | gmom | git merge origin/$(git_main_branch) |
| gmt | git mergetool --no-prompt | | gmt | git mergetool --no-prompt |
| gmtvim | git mergetool --no-prompt --tool=vimdiff | | gmtvim | git mergetool --no-prompt --tool=vimdiff |
| gmum | git merge upstream/master | | gmum | git merge upstream/$(git_main_branch) |
| gma | git merge --abort | | gma | git merge --abort |
| gp | git push | | gp | git push |
| gpd | git push --dry-run | | gpd | git push --dry-run |
@ -123,7 +123,7 @@ plugins=(... git)
| grbc | git rebase --continue | | grbc | git rebase --continue |
| grbd | git rebase develop | | grbd | git rebase develop |
| grbi | git rebase -i | | grbi | git rebase -i |
| grbm | git rebase master | | grbm | git rebase $(git_main_branch) |
| grbs | git rebase --skip | | grbs | git rebase --skip |
| grev | git revert | | grev | git revert |
| grh | git reset | | grh | git reset |
@ -170,7 +170,7 @@ plugins=(... git)
| gupv | git pull --rebase -v | | gupv | git pull --rebase -v |
| gupa | git pull --rebase --autostash | | gupa | git pull --rebase --autostash |
| gupav | git pull --rebase --autostash -v | | gupav | git pull --rebase --autostash -v |
| glum | git pull upstream master | | glum | git pull upstream $(git_main_branch) |
| gwch | git whatchanged -p --abbrev-commit --pretty=medium | | gwch | git whatchanged -p --abbrev-commit --pretty=medium |
| gwip | git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign -m "--wip-- [skip ci]" | | gwip | git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign -m "--wip-- [skip ci]" |
| gam | git am | | gam | git am |
@ -179,6 +179,13 @@ plugins=(... git)
| gama | git am --abort | | gama | git am --abort |
| gamscp | git am --show-current-patch | | gamscp | git am --show-current-patch |
### Main branch preference
Following the recent push for removing racially-charged words from our technical vocabulary, the git plugin favors using
a branch name other than `master`. In this case, we favor the shorter, neutral and descriptive term `main`. This means
that any aliases and functions that previously used `master`, will use `main` if that branch exists. We do this via the
function `git_main_branch`.
### Deprecated aliases ### Deprecated aliases
These are aliases that have been removed, renamed, or otherwise modified in a way that may, or may not, receive further support. These are aliases that have been removed, renamed, or otherwise modified in a way that may, or may not, receive further support.
@ -201,12 +208,13 @@ These are aliases that have been removed, renamed, or otherwise modified in a wa
### Current ### Current
| Command | Description | | Command | Description |
|:-----------------------|:---------------------------------------------------------| |:-----------------------|:-----------------------------------------------------------------------------|
| `grename <old> <new>` | Rename `old` branch to `new`, including in origin remote | | `grename <old> <new>` | Rename `old` branch to `new`, including in origin remote |
| current_branch | Return the name of the current branch | | current_branch | Return the name of the current branch |
| git_current_user_name | Returns the `user.name` config value | | git_current_user_name | Returns the `user.name` config value |
| git_current_user_email | Returns the `user.email` config value | | git_current_user_email | Returns the `user.email` config value |
| git_main_branch | Returns the name of the main branch: `main` if it exists, `master` otherwise |
### Work in Progress (WIP) ### Work in Progress (WIP)

View file

@ -25,6 +25,15 @@ function work_in_progress() {
fi fi
} }
# Check if main exists and use instead of master
function git_main_branch() {
if [[ -n "$(git branch --list main)" ]]; then
echo main
else
echo master
fi
}
# #
# Aliases # Aliases
# (sorted alphabetically) # (sorted alphabetically)
@ -43,7 +52,7 @@ alias gapt='git apply --3way'
alias gb='git branch' alias gb='git branch'
alias gba='git branch -a' alias gba='git branch -a'
alias gbd='git branch -d' alias gbd='git branch -d'
alias gbda='git branch --no-color --merged | command grep -vE "^(\+|\*|\s*(master|development|develop|devel|dev)\s*$)" | command xargs -n 1 git branch -d' alias gbda='git branch --no-color --merged | command grep -vE "^(\+|\*|\s*($(git_main_branch)|development|develop|devel|dev)\s*$)" | command xargs -n 1 git branch -d'
alias gbD='git branch -D' alias gbD='git branch -D'
alias gbl='git blame -b -w' alias gbl='git blame -b -w'
alias gbnm='git branch --no-merged' alias gbnm='git branch --no-merged'
@ -68,7 +77,7 @@ alias gcf='git config --list'
alias gcl='git clone --recurse-submodules' alias gcl='git clone --recurse-submodules'
alias gclean='git clean -id' alias gclean='git clean -id'
alias gpristine='git reset --hard && git clean -dffx' alias gpristine='git reset --hard && git clean -dffx'
alias gcm='git checkout master' alias gcm='git checkout $(git_main_branch)'
alias gcd='git checkout develop' alias gcd='git checkout develop'
alias gcmsg='git commit -m' alias gcmsg='git commit -m'
alias gco='git checkout' alias gco='git checkout'
@ -160,7 +169,7 @@ alias ghh='git help'
alias gignore='git update-index --assume-unchanged' alias gignore='git update-index --assume-unchanged'
alias gignored='git ls-files -v | grep "^[[:lower:]]"' alias gignored='git ls-files -v | grep "^[[:lower:]]"'
alias git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk' alias git-svn-dcommit-push='git svn dcommit && git push github $(git_main_branch):svntrunk'
alias gk='\gitk --all --branches' alias gk='\gitk --all --branches'
alias gke='\gitk --all $(git log -g --pretty=%h)' alias gke='\gitk --all $(git log -g --pretty=%h)'
@ -182,10 +191,10 @@ alias gloga='git log --oneline --decorate --graph --all'
alias glp="_git_log_prettily" alias glp="_git_log_prettily"
alias gm='git merge' alias gm='git merge'
alias gmom='git merge origin/master' alias gmom='git merge origin/$(git_main_branch)'
alias gmt='git mergetool --no-prompt' alias gmt='git mergetool --no-prompt'
alias gmtvim='git mergetool --no-prompt --tool=vimdiff' alias gmtvim='git mergetool --no-prompt --tool=vimdiff'
alias gmum='git merge upstream/master' alias gmum='git merge upstream/$(git_main_branch)'
alias gma='git merge --abort' alias gma='git merge --abort'
alias gp='git push' alias gp='git push'
@ -203,7 +212,7 @@ alias grba='git rebase --abort'
alias grbc='git rebase --continue' alias grbc='git rebase --continue'
alias grbd='git rebase develop' alias grbd='git rebase develop'
alias grbi='git rebase -i' alias grbi='git rebase -i'
alias grbm='git rebase master' alias grbm='git rebase $(git_main_branch)'
alias grbs='git rebase --skip' alias grbs='git rebase --skip'
alias grev='git revert' alias grev='git revert'
alias grh='git reset' alias grh='git reset'
@ -258,7 +267,7 @@ alias gup='git pull --rebase'
alias gupv='git pull --rebase -v' alias gupv='git pull --rebase -v'
alias gupa='git pull --rebase --autostash' alias gupa='git pull --rebase --autostash'
alias gupav='git pull --rebase --autostash -v' alias gupav='git pull --rebase --autostash -v'
alias glum='git pull upstream master' alias glum='git pull upstream $(git_main_branch)'
alias gwch='git whatchanged -p --abbrev-commit --pretty=medium' alias gwch='git whatchanged -p --abbrev-commit --pretty=medium'
alias gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign -m "--wip-- [skip ci]"' alias gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign -m "--wip-- [skip ci]"'