跳到主要内容

git plugin

The git plugin provides many aliases and a few useful functions.

To use it, add git to the plugins array in your zshrc file:

plugins=(... git)

Aliases

AliasCommand
grtcd "$(git rev-parse --show-toplevel || echo .)"
ggpnpggl && ggp
ggpurggu
ggit
gagit add
gaagit add --all
gapagit add --patch
gaugit add --update
gavgit add --verbose
gwipgit add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign --message "--wip-- [skip ci]"
gamgit am
gamagit am --abort
gamcgit am --continue
gamscpgit am --show-current-patch
gamsgit am --skip
gapgit apply
gaptgit apply --3way
gbsgit bisect
gbsbgit bisect bad
gbsggit bisect good
gbsngit bisect new
gbsogit bisect old
gbsrgit bisect reset
gbssgit bisect start
gblgit blame -w
gbgit branch
gbagit branch --all
gbdgit branch --delete
gbDgit branch --delete --force
gbgdLANG=C git branch --no-color -vv | grep ": gone\]" | cut -c 3- | awk '"'"'{print $1}'"'"' | xargs git branch -d
gbgDLANG=C git branch --no-color -vv | grep ": gone\]" | cut -c 3- | awk '"'"'{print $1}'"'"' | xargs git branch -D
gbmgit branch --move
gbnmgit branch --no-merged
gbrgit branch --remote
ggsupgit branch --set-upstream-to=origin/$(git_current_branch)
gbgLANG=C git branch -vv | grep ": gone\]"
gcogit checkout
gcorgit checkout --recurse-submodules
gcbgit checkout -b
gcBgit checkout -B
gcdgit checkout $(git_develop_branch)
gcmgit checkout $(git_main_branch)
gcpgit cherry-pick
gcpagit cherry-pick --abort
gcpcgit cherry-pick --continue
gcleangit clean --interactive -d
gclgit clone --recurse-submodules
gccdgit clone --recurse-submodules "$@" && cd "$(basename $\_ .git)"
gcamgit commit --all --message
gcasgit commit --all --signoff
gcasmgit commit --all --signoff --message
gcmsggit commit --message
gcsmgit commit --signoff --message
gcgit commit --verbose
gcagit commit --verbose --all
gca!git commit --verbose --all --amend
gcan!git commit --verbose --all --no-edit --amend
gcans!git commit --verbose --all --signoff --no-edit --amend
gcann!git commit --verbose --all --date=now --no-edit --amend
gc!git commit --verbose --amend
gcn!git commit --verbose --no-edit --amend
gcsgit commit -S
gcssgit commit -S -s
gcssmgit commit -S -s -m
gcfgit config --list
gdctgit describe --tags $(git rev-list --tags --max-count=1)
gdgit diff
gdcagit diff --cached
gdcwgit diff --cached --word-diff
gdsgit diff --staged
gdwgit diff --word-diff
gdvgit diff -w "$@" | view -
gdupgit diff @{upstream}
gdnolockgit diff $@ ":(exclude)package-lock.json" ":(exclude)\*.lock"
gdtgit diff-tree --no-commit-id --name-only -r
gfgit fetch
gfagit fetch --all --prune
gfogit fetch origin
gggit gui citool
ggagit gui citool --amend
ghhgit help
glgggit log --graph
glggagit log --graph --decorate --all
glgmgit log --graph --max-count=10
glodgit log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset'
glodsgit log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short
glolgit log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset'
glolagit log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --all
glolsgit log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --stat
glogit log --oneline --decorate
gloggit log --oneline --decorate --graph
glogagit log --oneline --decorate --graph --all
glpgit log --pretty=<format>
glggit log --stat
glgpgit log --stat --patch
gignoredgit ls-files -v | grep "^[[:lower:]]"
gfggit ls-files | grep
gmgit merge
gmagit merge --abort
gmcgit merge --continue
gmsgit merge --squash
gmomgit merge origin/$(git_main_branch)
gmumgit merge upstream/$(git_main_branch)
gmtlgit mergetool --no-prompt
gmtlvimgit mergetool --no-prompt --tool=vimdiff
glgit pull
gprgit pull --rebase
gprvgit pull --rebase -v
gpragit pull --rebase --autostash
gpravgit pull --rebase --autostash -v
gpromgit pull --rebase origin $(git_main_branch)
gpromigit pull --rebase=interactive origin $(git_main_branch)
ggpullgit pull origin "$(git_current_branch)"
gglgit pull origin $(current_branch)
glucgit pull upstream $(git_current_branch)
glumgit pull upstream $(git_main_branch)
gpgit push
gpdgit push --dry-run
gpf!git push --force
ggfgit push --force origin $(current_branch)
gpfOn Git >= 2.30: git push --force-with-lease --force-if-includes
gpfOn Git < 2.30: git push --force-with-lease
ggflgit push --force-with-lease origin $(current_branch)
gpsupgit push --set-upstream origin $(git_current_branch)
gpsupfOn Git >= 2.30: git push --set-upstream origin $(git_current_branch) --force-with-lease --force-if-includes
gpsupfOn Git < 2.30: git push --set-upstream origin $(git_current_branch) --force-with-lease
gpvgit push --verbose
gpoatgit push origin --all && git push origin --tags
gpodgit push origin --delete
ggpushgit push origin "$(git_current_branch)"
ggpgit push origin $(current_branch)
gpugit push upstream
grbgit rebase
grbagit rebase --abort
grbcgit rebase --continue
grbigit rebase --interactive
grbogit rebase --onto
grbsgit rebase --skip
grbdgit rebase $(git_develop_branch)
grbmgit rebase $(git_main_branch)
grbomgit rebase origin/$(git_main_branch)
grfgit reflog
grgit remote
grvgit remote --verbose
gragit remote add
grrmgit remote remove
grmvgit remote rename
grsetgit remote set-url
grupgit remote update
grhgit reset
grugit reset --
grhhgit reset --hard
grhkgit reset --keep
grhsgit reset --soft
gpristinegit reset --hard && git clean --force -dfx
gwipegit reset --hard && git clean --force -df
grohgit reset origin/$(git_current_branch) --hard
grsgit restore
grssgit restore --source
grstgit restore --staged
gunwipgit rev-list --max-count=1 --format="%s" HEAD | grep -q "--wip--" && git reset HEAD~1
grevgit revert
grmgit rm
grmcgit rm --cached
gcountgit shortlog --summary -n
gshgit show
gspsgit show --pretty=short --show-signature
gstallgit stash --all
gstugit stash --include-untracked
gstaagit stash apply
gstcgit stash clear
gstdgit stash drop
gstlgit stash list
gstpgit stash pop
gstaOn Git >= 2.13: git stash push
gstaOn Git < 2.13: git stash save
gstsgit stash show --patch
gstgit status
gssgit status --short
gsbgit status --short -b
gsigit submodule init
gsugit submodule update
gsdgit svn dcommit
git-svn-dcommit-pushgit svn dcommit && git push github $(git_main_branch):svntrunk
gsrgit svn rebase
gswgit switch
gswcgit switch -c
gswdgit switch $(git_develop_branch)
gswmgit switch $(git_main_branch)
gtagit tag --annotate
gtsgit tag -s
gtvgit tag | sort -V
gignoregit update-index --assume-unchanged
gunignoregit update-index --no-assume-unchanged
gwchgit whatchanged -p --abbrev-commit --pretty=medium
gwtgit worktree
gwtlsgit worktree list
gwtmvgit worktree move
gwtrmgit worktree remove
gkgitk --all --branches &!
gkegitk --all $(git log --walk-reflogs --pretty=%h) &!
gtlgtl(){ git tag --sort=-v:refname -n --list ${1}\* }; noglob gtl

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

These are aliases that have been removed, renamed, or otherwise modified in a way that may, or may not, receive further support.

AliasCommandModification
gapgit add --patchNew alias: gapa.
gclgit config --listNew alias: gcf.
gdcgit diff --cachedNew alias: gdca.
gdtgit difftoolNo replacement.
ggpullgit pull origin $(current_branch)New alias: ggl. (ggpull still exists for now though.)
ggpurgit pull --rebase origin $(current_branch)New alias: ggu. (ggpur still exists for now though.)
ggpushgit push origin $(current_branch)New alias: ggp. (ggpush still exists for now though.)
gkgitk --all --branchesNow aliased to gitk --all --branches.
glggit log --stat --max-count=10Now aliased to git log --stat --color.
glgggit log --graph --max-count=10Now aliased to git log --graph --color.
gwcgit whatchanged -p --abbrev-commit --pretty = mediumNew alias: gwch.
gupgit pull --rebasenow alias gpr
gupvgit pull --rebase -vnow alias gprv
gupagit pull --rebase --autostashnow alias gpra
gupavgit pull --rebase --autostash -vnow alias gprav
gupomgit pull --rebase origin $(git_main_branch)now alias gprom
gupomigit pull --rebase=interactive origin $(git_main_branch)now alias gpromi

Functions

Current

CommandDescription
current_branchReturns the name of the current branch.
git_current_user_emailReturns the user.email config value. (Lives in lib/git.zsh.)
git_current_user_nameReturns the user.name config value. (Lives in lib/git.zsh.)
git_develop_branchReturns the name of the “development” branch: dev, devel, development if they exist, develop otherwise.
git_main_branchReturns the name of the main branch: main if it exists, master otherwise.
grename <old> <new>Renames branch <old> to <new>, including on the origin remote.
gbdaDeletes all merged branches
gbdsDeletes all squash-merged branches (Note: performance degrades with number of branches)

Work in Progress (WIP)

These features allow you to pause developing one branch and switch to another one ("Work in Progress", or “wip”). When you want to go back to work, just “unwip” it.

CommandDescription
gwipCommit wip branch
gunwipUncommit wip branch
gunwipallUncommit all recent --wip-- commits
work_in_progressEchoes a warning if the current branch is a wip

Note that gwip and gunwip are aliases, but are also documented here to group all related WIP features.

Deprecated functions

CommandDescriptionReason
current_repositoryReturn the names of the current remotesDidn't work properly. Use git remote -v instead (grv alias).