58 KiB
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
| Alias | Command | Description |
|---|---|---|
grt |
cd "$(git rev-parse --show-toplevel || echo .)" |
Navigate to the root directory of the current git repository |
ggpnp |
ggl && ggp |
Pull from origin and then push to origin (pull and push) |
ggpur |
ggu |
Pull with rebase from upstream |
g |
git |
Short alias for git command |
ga |
git add |
Add files to the staging area |
gaa |
git add --all |
Add all changes (including new, modified, and deleted files) to staging area |
gapa |
git add --patch |
Interactively add changes to staging area by selecting hunks |
gau |
git add --update |
Add only modified and deleted files to staging area (no new files) |
gav |
git add --verbose |
Add files to staging area with verbose output showing what was added |
gwip |
git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign --message "--wip-- [skip ci]" |
Create a work-in-progress commit with all changes and skip CI |
gam |
git am |
Apply patches from mailbox format |
gama |
git am --abort |
Abort the current patch application process |
gamc |
git am --continue |
Continue applying patches after resolving conflicts |
gamscp |
git am --show-current-patch |
Show the current patch being applied |
gams |
git am --skip |
Skip the current patch and continue with the next one |
gap |
git apply |
Apply a patch to files and/or to the index |
gapt |
git apply --3way |
Apply patch using 3-way merge when conflicts occur |
gbs |
git bisect |
Start or manage binary search to find problematic commit |
gbsb |
git bisect bad |
Mark current commit as bad during bisect |
gbsg |
git bisect good |
Mark current commit as good during bisect |
gbsn |
git bisect new |
Mark current commit as new (bad) during bisect |
gbso |
git bisect old |
Mark current commit as old (good) during bisect |
gbsr |
git bisect reset |
End bisect session and return to original branch |
gbss |
git bisect start |
Start a new bisect session |
gbl |
git blame -w |
Show who last modified each line of a file, ignoring whitespace changes |
gb |
git branch |
List, create, or delete branches |
gba |
git branch --all |
List all branches (local and remote) |
gbd |
git branch --delete |
Delete a branch (safe delete, only if merged) |
gbD |
git branch --delete --force |
Force delete a branch regardless of merge status |
gbgd |
LANG=C git branch --no-color -vv | grep ": gone\]" | cut -c 3- | awk '"'"'{print $1}'"'"' | xargs git branch -d |
Delete local branches that track deleted remote branches (safe delete) |
gbgD |
LANG=C git branch --no-color -vv | grep ": gone\]" | cut -c 3- | awk '"'"'{print $1}'"'"' | xargs git branch -D |
Force delete local branches that track deleted remote branches |
gbm |
git branch --move |
Rename/move a branch |
gbnm |
git branch --no-merged |
List branches that are not merged into current branch |
gbr |
git branch --remote |
List remote-tracking branches |
ggsup |
git branch --set-upstream-to=origin/$(git_current_branch) |
Set upstream tracking for current branch to origin |
gbg |
LANG=C git branch -vv | grep ": gone\]" |
Show local branches that track deleted remote branches |
gco |
git checkout |
Switch branches or restore working tree files |
gcor |
git checkout --recurse-submodules |
Checkout and recursively update submodules |
gcb |
git checkout -b |
Create and switch to a new branch |
gcB |
git checkout -B |
Create or reset and switch to a branch |
gcd |
git checkout $(git_develop_branch) |
Switch to the development branch (dev, devel, development, or develop) |
gcm |
git checkout $(git_main_branch) |
Switch to the main branch (main or master) |
gcp |
git cherry-pick |
Apply commits from another branch to current branch |
gcpa |
git cherry-pick --abort |
Abort cherry-pick operation |
gcpc |
git cherry-pick --continue |
Continue cherry-pick after resolving conflicts |
gclean |
git clean --interactive -d |
Interactively remove untracked files and directories |
gcl |
git clone --recurse-submodules |
Clone a repository and recursively clone its submodules |
gclf |
git clone --recursive --shallow-submodules --filter=blob:none --also-filter-submodules |
Clone repository with filtered blobs and shallow submodules for faster cloning |
gccd |
git clone --recurse-submodules "$@" && cd "$(basename $\_ .git)" |
Clone repository with submodules and change to the cloned directory |
gcam |
git commit --all --message |
Commit all changes with a message |
gcas |
git commit --all --signoff |
Commit all changes and add signed-off-by line |
gcasm |
git commit --all --signoff --message |
Commit all changes with message and signed-off-by line |
gcmsg |
git commit --message |
Create a commit with a message |
gcsm |
git commit --signoff --message |
Create a commit with message and signed-off-by line |
gc |
git commit --verbose |
Create a commit with verbose output showing diff |
gca |
git commit --verbose --all |
Commit all changes with verbose output |
gca! |
git commit --verbose --all --amend |
Amend last commit with all current changes and verbose output |
gcan! |
git commit --verbose --all --no-edit --amend |
Amend last commit with all changes without editing message |
gcans! |
git commit --verbose --all --signoff --no-edit --amend |
Amend last commit with all changes, add sign-off, no edit |
gcann! |
git commit --verbose --all --date=now --no-edit --amend |
Amend last commit with current timestamp, all changes, no edit |
gc! |
git commit --verbose --amend |
Amend last commit with verbose output |
gcn |
git commit --verbose --no-edit |
Create commit with verbose output but no editor |
gcn! |
git commit --verbose --no-edit --amend |
Amend last commit without opening editor |
gcs |
git commit -S |
Create a GPG-signed commit |
gcss |
git commit -S -s |
Create a GPG-signed commit with sign-off |
gcssm |
git commit -S -s -m |
Create a GPG-signed commit with sign-off and message |
gcf |
git config --list |
List all git configuration settings |
gcfu |
git commit --fixup |
Create a fixup commit for later use with rebase --autosquash |
gdct |
git describe --tags $(git rev-list --tags --max-count=1) |
Show the most recent tag |
gd |
git diff |
Show changes between working directory and staging area |
gdca |
git diff --cached |
Show changes between staging area and last commit |
gdcw |
git diff --cached --word-diff |
Show word-level changes between staging area and last commit |
gds |
git diff --staged |
Show changes between staging area and last commit (same as gdca) |
gdw |
git diff --word-diff |
Show word-level changes between working directory and staging area |
gdv |
git diff -w "$@" | view - |
Show diff ignoring whitespace and pipe to view |
gdup |
git diff @{upstream} |
Show diff between current branch and its upstream |
gdnolock |
git diff $@ ":(exclude)package-lock.json" ":(exclude)\*.lock" |
Show diff excluding lock files |
gdt |
git diff-tree --no-commit-id --name-only -r |
Show only the names of changed files in a commit |
gf |
git fetch |
Download objects and refs from remote repository |
gfa |
git fetch --all --tags --prune |
Fetch from all remotes, download tags, and prune deleted branches |
gfo |
git fetch origin |
Fetch from origin remote |
gg |
git gui citool |
Open git GUI commit tool |
gga |
git gui citool --amend |
Open git GUI commit tool to amend last commit |
ghh |
git help |
Show git help documentation |
glgg |
git log --graph |
Show commit history as a graph |
glgga |
git log --graph --decorate --all |
Show commit history graph with decorations for all branches |
glgm |
git log --graph --max-count=10 |
Show last 10 commits as a graph |
glod |
git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' |
Show commit log with colored format including absolute dates |
glods |
git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short |
Show commit log with colored format and short dates |
glol |
git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' |
Show commit log with colored format including relative dates |
glola |
git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --all |
Show commit log with colored format for all branches |
glols |
git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --stat |
Show commit log with colored format and file change statistics |
glo |
git log --oneline --decorate |
Show compact one-line commit history with decorations |
glog |
git log --oneline --decorate --graph |
Show compact one-line commit history as a graph |
gloga |
git log --oneline --decorate --graph --all |
Show compact one-line commit history graph for all branches |
glp |
git log --pretty=<format> |
Show commit log with custom pretty format |
glg |
git log --stat |
Show commit history with file change statistics |
glgp |
git log --stat --patch |
Show commit history with statistics and full patch content |
gignored |
git ls-files -v | grep "^[[:lower:]]" |
List files that are ignored or assume-unchanged |
gfg |
git ls-files | grep |
Search for files in git repository by pattern |
gm |
git merge |
Merge branches together |
gma |
git merge --abort |
Abort current merge operation |
gmc |
git merge --continue |
Continue merge after resolving conflicts |
gms |
git merge --squash |
Merge branch and squash commits into single commit |
gmff |
git merge --ff-only |
Merge only if fast-forward is possible |
gmom |
git merge origin/$(git_main_branch) |
Merge origin's main branch into current branch |
gmum |
git merge upstream/$(git_main_branch) |
Merge upstream's main branch into current branch |
gmtl |
git mergetool --no-prompt |
Run merge tool without prompting |
gmtlvim |
git mergetool --no-prompt --tool=vimdiff |
Run vimdiff as merge tool without prompting |
gl |
git pull |
Pull changes from remote repository |
gpr |
git pull --rebase |
Pull and rebase instead of merge |
gprv |
git pull --rebase -v |
Pull and rebase with verbose output |
gpra |
git pull --rebase --autostash |
Pull and rebase with automatic stashing of local changes |
gprav |
git pull --rebase --autostash -v |
Pull and rebase with autostash and verbose output |
gprom |
git pull --rebase origin $(git_main_branch) |
Pull and rebase from origin's main branch |
gpromi |
git pull --rebase=interactive origin $(git_main_branch) |
Interactive pull and rebase from origin's main branch |
gprum |
git pull --rebase upstream $(git_main_branch) |
Pull and rebase from upstream's main branch |
gprumi |
git pull --rebase=interactive upstream $(git_main_branch) |
Interactive pull and rebase from upstream's main branch |
ggpull |
git pull origin "$(git_current_branch)" |
Pull from origin using current branch name |
ggl |
git pull origin $(current_branch) |
Pull from origin for current branch |
gluc |
git pull upstream $(git_current_branch) |
Pull from upstream for current branch |
glum |
git pull upstream $(git_main_branch) |
Pull from upstream's main branch |
gp |
git push |
Push commits to remote repository |
gpd |
git push --dry-run |
Show what would be pushed without actually pushing |
gpf! |
git push --force |
Force push (dangerous - rewrites remote history) |
ggf |
git push --force origin $(current_branch) |
Force push current branch to origin |
gpf |
On Git >= 2.30: git push --force-with-lease --force-if-includes |
Safer force push that checks if remote was updated |
gpf |
On Git < 2.30: git push --force-with-lease |
Safer force push that checks if remote was updated (older git) |
ggfl |
git push --force-with-lease origin $(current_branch) |
Force push current branch with lease protection |
gpsup |
git push --set-upstream origin $(git_current_branch) |
Push and set upstream tracking for current branch |
gpsupf |
On Git >= 2.30: git push --set-upstream origin $(git_current_branch) --force-with-lease --force-if-includes |
Push with upstream and force-with-lease protection |
gpsupf |
On Git < 2.30: git push --set-upstream origin $(git_current_branch) --force-with-lease |
Push with upstream and force-with-lease protection (older git) |
gpv |
git push --verbose |
Push with verbose output |
gpoat |
git push origin --all && git push origin --tags |
Push all branches and tags to origin |
gpod |
git push origin --delete |
Delete a branch or tag on origin remote |
ggpush |
git push origin "$(git_current_branch)" |
Push current branch to origin |
ggp |
git push origin $(current_branch) |
Push current branch to origin |
gpu |
git push upstream |
Push to upstream remote |
grb |
git rebase |
Reapply commits on top of another base tip |
grba |
git rebase --abort |
Abort current rebase operation |
grbc |
git rebase --continue |
Continue rebase after resolving conflicts |
grbi |
git rebase --interactive |
Start interactive rebase to edit commits |
grbo |
git rebase --onto |
Rebase commits onto a specific commit |
grbs |
git rebase --skip |
Skip current commit during rebase |
grbd |
git rebase $(git_develop_branch) |
Rebase current branch onto development branch |
grbm |
git rebase $(git_main_branch) |
Rebase current branch onto main branch |
grbom |
git rebase origin/$(git_main_branch) |
Rebase current branch onto origin's main branch |
grbum |
git rebase upstream/$(git_main_branch) |
Rebase current branch onto upstream's main branch |
grf |
git reflog |
Show reference logs (history of branch tips) |
gr |
git remote |
List remote repositories |
grv |
git remote --verbose |
List remote repositories with URLs |
gra |
git remote add |
Add a new remote repository |
grrm |
git remote remove |
Remove a remote repository |
grmv |
git remote rename |
Rename a remote repository |
grset |
git remote set-url |
Change URL of a remote repository |
grup |
git remote update |
Update all remote-tracking branches |
grh |
git reset |
Reset current HEAD to specified state |
gru |
git reset -- |
Unstage files (reset from staging area) |
grhh |
git reset --hard |
Reset working directory and staging area to match commit |
grhk |
git reset --keep |
Reset HEAD but keep local changes |
grhs |
git reset --soft |
Reset HEAD but keep staging area and working directory |
gpristine |
git reset --hard && git clean --force -dfx |
Reset to clean state, removing all untracked files and changes |
gwipe |
git reset --hard && git clean --force -df |
Reset and clean working directory (keeping ignored files) |
groh |
git reset origin/$(git_current_branch) --hard |
Hard reset to match origin's version of current branch |
grs |
git restore |
Restore working tree files |
grss |
git restore --source |
Restore files from a specific source |
grst |
git restore --staged |
Unstage files (restore from staging area) |
gunwip |
git rev-list --max-count=1 --format="%s" HEAD | grep -q "--wip--" && git reset HEAD~1 |
Remove work-in-progress commit if it exists |
grev |
git revert |
Create new commit that undoes changes from previous commits |
grm |
git rm |
Remove files from working tree and staging area |
grmc |
git rm --cached |
Remove files from staging area but keep in working directory |
gcount |
git shortlog --summary -n |
Show commit count by author, sorted by number of commits |
gsh |
git show |
Show information about commits, tags, or other objects |
gsps |
git show --pretty=short --show-signature |
Show commit with short format and signature verification |
gstall |
git stash --all |
Stash all changes including untracked and ignored files |
gstu |
git stash --include-untracked |
Stash changes including untracked files |
gstaa |
git stash apply |
Apply most recent stash without removing it |
gstc |
git stash clear |
Delete all stashes |
gstd |
git stash drop |
Delete most recent stash |
gstl |
git stash list |
List all stashes |
gstp |
git stash pop |
Apply and remove most recent stash |
gsta |
On Git >= 2.13: git stash push |
Create a new stash with optional message and pathspec |
gsta |
On Git < 2.13: git stash save |
Create a new stash with message (older git versions) |
gsts |
git stash show --patch |
Show changes in most recent stash as a patch |
gst |
git status |
Show working tree status |
gss |
git status --short |
Show working tree status in short format |
gsb |
git status --short -b |
Show short status with branch information |
gsi |
git submodule init |
Initialize git submodules |
gsu |
git submodule update |
Update git submodules to match superproject |
gsd |
git svn dcommit |
Commit to SVN repository (git-svn) |
git-svn-dcommit-push |
git svn dcommit && git push github $(git_main_branch):svntrunk |
Commit to SVN and push to GitHub |
gsr |
git svn rebase |
Rebase from SVN repository (git-svn) |
gsw |
git switch |
Switch to a different branch |
gswc |
git switch -c |
Create and switch to a new branch |
gswd |
git switch $(git_develop_branch) |
Switch to development branch |
gswm |
git switch $(git_main_branch) |
Switch to main branch |
gta |
git tag --annotate |
Create an annotated tag |
gts |
git tag -s |
Create a GPG-signed tag |
gtv |
git tag | sort -V |
List tags sorted by version numbers |
gignore |
git update-index --assume-unchanged |
Mark files as unchanged to ignore local modifications |
gunignore |
git update-index --no-assume-unchanged |
Stop ignoring local modifications to files |
gwch |
git whatchanged -p --abbrev-commit --pretty=medium |
Show commit history with patches and abbreviated commit hashes |
gwt |
git worktree |
Manage multiple working trees |
gwtls |
git worktree list |
List all working trees |
gwtmv |
git worktree move |
Move a working tree to a new location |
gwtrm |
git worktree remove |
Remove a working tree |
gk |
gitk --all --branches &! |
Open gitk GUI showing all branches in background |
gke |
gitk --all $(git log --walk-reflogs --pretty=%h) &! |
Open gitk GUI showing all reflog entries in background |
gtl |
gtl(){ git tag --sort=-v:refname -n --list ${1}\* }; noglob gtl |
List tags matching pattern, sorted by version in descending order |
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.
| Alias | Command | Modification |
|---|---|---|
gap |
git add --patch |
New alias: gapa. |
gcl |
git config --list |
New alias: gcf. |
gdc |
git diff --cached |
New alias: gdca. |
gdt |
git difftool |
No replacement. |
ggpull |
git pull origin $(current_branch) |
New alias: ggl. (ggpull still exists for now though.) |
ggpur |
git pull --rebase origin $(current_branch) |
New alias: ggu. (ggpur still exists for now though.) |
ggpush |
git push origin $(current_branch) |
New alias: ggp. (ggpush still exists for now though.) |
gk |
gitk --all --branches |
Now aliased to gitk --all --branches. |
glg |
git log --stat --max-count=10 |
Now aliased to git log --stat --color. |
glgg |
git log --graph --max-count=10 |
Now aliased to git log --graph --color. |
gwc |
git whatchanged -p --abbrev-commit --pretty = medium |
New alias: gwch. |
gup |
git pull --rebase |
now alias gpr |
gupv |
git pull --rebase -v |
now alias gprv |
gupa |
git pull --rebase --autostash |
now alias gpra |
gupav |
git pull --rebase --autostash -v |
now alias gprav |
gupom |
git pull --rebase origin $(git_main_branch) |
now alias gprom |
gupomi |
git pull --rebase=interactive origin $(git_main_branch) |
now alias gpromi |
Functions
Current
| Command | Description |
|---|---|
current_branch |
Returns the name of the current branch. |
git_current_user_email |
Returns the user.email config value. (Lives in lib/git.zsh.) |
git_current_user_name |
Returns the user.name config value. (Lives in lib/git.zsh.) |
git_develop_branch |
Returns the name of the “development” branch: dev, devel, development if they exist, develop otherwise. |
git_main_branch |
Returns 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. |
gbda |
Deletes all merged branches |
gbds |
Deletes 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.
| Command | Description |
|---|---|
gwip |
Commit wip branch |
gunwip |
Uncommit wip branch |
gunwipall |
Uncommit all recent --wip-- commits |
work_in_progress |
Echoes 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
| Command | Description | Reason |
|---|---|---|
current_repository |
Return the names of the current remotes | Didn't work properly. Use git remote -v instead (grv alias). |