Based on ohmyzsh/plugins/git at beadd56dd75e8a40fe0a7d4a5d63ed5bf9efcd48 · ohmyzsh/ohmyzsh · GitHub

Git Aliases with Explanations

AliasCommandExplanation
grtcd "$(git rev-parse --show-toplevel | echo .)"Jump to repository root directory
ggpnpggl && ggpPull then push current branch (sync with origin)
ggpurgguAlias for ggu (pull rebase current branch)
ggitShorthand for git
gagit addStage specific files
gaagit add --allStage all changes (new, modified, deleted)
gapagit add --patchInteractively stage hunks of changes
gaugit add --updateStage only modified/deleted files (not new)
gavgit add --verboseStage with verbose output
gwipgit add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign --message "--wip-- [skip ci]"Quick work-in-progress commit (skips hooks/CI)
gamgit amApply patches from mailbox
gamagit am --abortAbort patch application
gamcgit am --continueContinue after resolving conflicts
gamscpgit am --show-current-patchShow the patch being applied
gamsgit am --skipSkip current patch
gapgit applyApply a patch to files
gaptgit apply --3wayApply patch with 3-way merge for conflicts
gbsgit bisectBinary search for bug-introducing commit
gbsbgit bisect badMark current commit as bad
gbsggit bisect goodMark current commit as good
gbsngit bisect newMark commit as new (alternative to bad)
gbsogit bisect oldMark commit as old (alternative to good)
gbsrgit bisect resetEnd bisect session
gbssgit bisect startStart bisect session
gblgit blame -wShow line-by-line authorship (ignore whitespace)
gbgit branchList local branches
gbagit branch --allList all branches (local + remote)
gbdgit branch --deleteDelete a merged branch
gbDgit branch --delete --forceForce delete a branch (even unmerged)
gbgdLANG=C git branch --no-color -vv | grep ": gone\]" | ...Delete local branches whose remote is gone
gbgDLANG=C git branch --no-color -vv | grep ": gone\]" | ...Force delete branches whose remote is gone
gbmgit branch --moveRename a branch
gbnmgit branch --no-mergedList branches not merged into current
gbrgit branch --remoteList remote branches
ggsupgit branch --set-upstream-to=origin/$(git_current_branch)Set upstream tracking for current branch
gbgLANG=C git branch -vv | grep ": gone\]"Show branches whose remote tracking is gone
gcogit checkoutSwitch branches or restore files
gcorgit checkout --recurse-submodulesCheckout with submodule update
gcbgit checkout -bCreate and switch to new branch
gcBgit checkout -BCreate/reset and switch to branch
gcdgit checkout $(git_develop_branch)Switch to develop branch
gcmgit checkout $(git_main_branch)Switch to main/master branch
gcpgit cherry-pickApply specific commit(s) to current branch
gcpagit cherry-pick --abortAbort cherry-pick
gcpcgit cherry-pick --continueContinue cherry-pick after resolving conflicts
gcleangit clean --interactive -dInteractively remove untracked files/dirs
gclgit clone --recurse-submodulesClone repo including submodules
gclfgit clone --recursive --shallow-submodules --filter=blob:none --also-filter-submodulesFast clone (partial clone, shallow submodules)
gccdgit clone --recurse-submodules "$@" && cd "$(basename $_ .git)"Clone and cd into the repo
gcamgit commit --all --messageStage all and commit with message
gcasgit commit --all --signoffStage all and commit with sign-off
gcasmgit commit --all --signoff --messageStage all, sign-off, with message
gcmsggit commit --messageCommit staged changes with message
gcsmgit commit --signoff --messageCommit with sign-off and message
gcgit commit --verboseCommit showing diff in editor
gcagit commit --verbose --allStage all and commit with diff in editor
gca!git commit --verbose --all --amendAmend last commit, staging all changes
gcan!git commit --verbose --all --no-edit --amendAmend last commit silently (keep message)
gcans!git commit --verbose --all --signoff --no-edit --amendAmend with sign-off, keep message
gcann!git commit --verbose --all --date=now --no-edit --amendAmend with current timestamp
gc!git commit --verbose --amendAmend last commit
gcngit commit --verbose --no-editCommit without editing message
gcn!git commit --verbose --no-edit --amendAmend without editing message
gcsgit commit -SCommit with GPG signature
gcssgit commit -S -sCommit with GPG signature and sign-off
gcssmgit commit -S -s -mGPG signed commit with sign-off and message
gcfgit config --listList all git configuration
gcfugit commit --fixupCreate fixup commit for autosquash
gdctgit describe --tags $(git rev-list --tags --max-count=1)Show most recent tag
gdgit diffShow unstaged changes
gdcagit diff --cachedShow staged changes
gdcwgit diff --cached --word-diffShow staged changes word-by-word
gdsgit diff --stagedShow staged changes (same as —cached)
gdwgit diff --word-diffShow unstaged changes word-by-word
gdvgit diff -w "$@" | view -View diff ignoring whitespace in vim
gdupgit diff @{upstream}Diff against upstream branch
gdnolockgit diff $@ ":(exclude)package-lock.json" ":(exclude)*.lock"Diff excluding lock files
gdtgit diff-tree --no-commit-id --name-only -rList files changed in a commit
gfgit fetchDownload objects/refs from remote
gfagit fetch --all --tags --pruneFetch all remotes, tags, prune stale refs
gfogit fetch originFetch from origin
gggit gui citoolOpen git GUI for committing
ggagit gui citool --amendOpen git GUI to amend
ghhgit helpShow git help
glgggit log --graphLog with ASCII branch graph
glggagit log --graph --decorate --allGraph log of all branches with decorations
glgmgit log --graph --max-count=10Graph log limited to 10 commits
glodgit log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset'Pretty graph log with author date
glodsgit log --graph --pretty='...' --date=shortPretty graph log with short dates
glolgit log --graph --pretty='...'Pretty graph log with relative dates
glolagit log --graph --pretty='...' --allPretty graph log of all branches
glolsgit log --graph --pretty='...' --statPretty graph log with file stats
glogit log --oneline --decorateCompact one-line log
gloggit log --oneline --decorate --graphCompact log with graph
glogagit log --oneline --decorate --graph --allCompact graph log of all branches
glpgit log --pretty=<format>Log with custom format
glggit log --statLog with diffstat
glgpgit log --stat --patchLog with diffstat and full diff
gignoredgit ls-files -v | grep "^[[:lower:]]"List files marked assume-unchanged
gfggit ls-files | grepSearch tracked filenames
gmgit mergeMerge branches
gmagit merge --abortAbort merge
gmcgit merge --continueContinue merge after resolving conflicts
gmsgit merge --squashSquash merge (combine into single commit)
gmffgit merge --ff-onlyMerge only if fast-forward possible
gmomgit merge origin/$(git_main_branch)Merge origin’s main into current
gmumgit merge upstream/$(git_main_branch)Merge upstream’s main into current
gmtlgit mergetool --no-promptLaunch merge tool
gmtlvimgit mergetool --no-prompt --tool=vimdiffLaunch vimdiff as merge tool
glgit pullFetch and merge from upstream
gprgit pull --rebaseFetch and rebase onto upstream
gprvgit pull --rebase -vVerbose pull with rebase
gpragit pull --rebase --autostashPull rebase, auto-stashing local changes
gpravgit pull --rebase --autostash -vVerbose pull rebase with autostash
gpromgit pull --rebase origin $(git_main_branch)Rebase current branch onto origin/main
gpromigit pull --rebase=interactive origin $(git_main_branch)Interactive rebase onto origin/main
gprumgit pull --rebase upstream $(git_main_branch)Rebase onto upstream/main
gprumigit pull --rebase=interactive upstream $(git_main_branch)Interactive rebase onto upstream/main
ggpullgit pull origin "$(git_current_branch)"Pull current branch from origin
gglgit pull origin $(current_branch)Pull current branch from origin
glucgit pull upstream $(git_current_branch)Pull current branch from upstream
glumgit pull upstream $(git_main_branch)Pull main from upstream
gpgit pushPush to remote
gpdgit push --dry-runSimulate push
gpf!git push --forceForce push (dangerous!)
ggfgit push --force origin $(current_branch)Force push current branch
gpfgit push --force-with-lease --force-if-includesSafe force push (checks for upstream changes)
ggflgit push --force-with-lease origin $(current_branch)Safe force push current branch
gpsupgit push --set-upstream origin $(git_current_branch)Push and set upstream tracking
gpsupfgit push --set-upstream origin $(git_current_branch) --force-with-lease --force-if-includesForce push and set upstream
gpvgit push --verboseVerbose push
gpoatgit push origin --all && git push origin --tagsPush all branches and tags
gpodgit push origin --deleteDelete remote branch
ggpushgit push origin "$(git_current_branch)"Push current branch to origin
ggpgit push origin $(current_branch)Push current branch to origin
gpugit push upstreamPush to upstream remote
grbgit rebaseRebase current branch
grbagit rebase --abortAbort rebase
grbcgit rebase --continueContinue rebase after resolving conflicts
grbigit rebase --interactiveInteractive rebase (edit/squash/reorder)
grbogit rebase --ontoRebase onto different base
grbsgit rebase --skipSkip current commit in rebase
grbdgit rebase $(git_develop_branch)Rebase onto develop
grbmgit rebase $(git_main_branch)Rebase onto main
grbomgit rebase origin/$(git_main_branch)Rebase onto origin/main
grbumgit rebase upstream/$(git_main_branch)Rebase onto upstream/main
grfgit reflogShow reference log (recovery tool)
grgit remoteManage remotes
grvgit remote --verboseList remotes with URLs
gragit remote addAdd a remote
grrmgit remote removeRemove a remote
grmvgit remote renameRename a remote
grsetgit remote set-urlChange remote URL
grupgit remote updateFetch updates from all remotes
grhgit resetReset HEAD (mixed mode)
grugit reset --Unstage files
grhhgit reset --hardReset HEAD, index, and working tree
grhkgit reset --keepReset keeping local changes if possible
grhsgit reset --softReset HEAD only (keep staged)
gpristinegit reset --hard && git clean --force -dfxNuclear reset (removes everything including ignored)
gwipegit reset --hard && git clean --force -dfHard reset + clean untracked (keeps ignored)
grohgit reset origin/$(git_current_branch) --hardHard reset to origin’s version
grsgit restoreRestore working tree files
grssgit restore --sourceRestore from specific source
grstgit restore --stagedUnstage files (restore index)
gunwipgit rev-list --max-count=1 --format="%s" HEAD | grep -q "--wip--" && git reset HEAD~1Undo WIP commit
grevgit revertCreate commit that undoes another
grmgit rmRemove files from index and working tree
grmcgit rm --cachedRemove from index only (untrack)
gcountgit shortlog --summary -nCount commits per author
gshgit showShow commit details and diff
gspsgit show --pretty=short --show-signatureShow commit with GPG signature
gstallgit stash --allStash everything including ignored
gstugit stash --include-untrackedStash including untracked files
gstaagit stash applyApply stash without removing it
gstcgit stash clearDelete all stashes
gstdgit stash dropDelete a specific stash
gstlgit stash listList all stashes
gstpgit stash popApply and remove stash
gstagit stash pushCreate new stash
gstsgit stash show --patchShow stash contents as diff
gstgit statusShow working tree status
gssgit status --shortCompact status
gsbgit status --short -bCompact status with branch info
gsigit submodule initInitialize submodules
gsugit submodule updateUpdate submodules
gsdgit svn dcommitPush to SVN
gsrgit svn rebaseRebase from SVN
gswgit switchSwitch branches (modern checkout)
gswcgit switch -cCreate and switch to new branch
gswdgit switch $(git_develop_branch)Switch to develop
gswmgit switch $(git_main_branch)Switch to main
gtagit tag --annotateCreate annotated tag
gtsgit tag -sCreate GPG-signed tag
gtvgit tag | sort -VList tags sorted by version
gignoregit update-index --assume-unchangedIgnore local changes to tracked file
gunignoregit update-index --no-assume-unchangedStop ignoring local changes
gwchgit log --patch --abbrev-commit --pretty=medium --rawDetailed log with patches
gwtgit worktreeManage multiple working trees
gwtlsgit worktree listList worktrees
gwtmvgit worktree moveMove worktree
gwtrmgit worktree removeRemove worktree
gkgitk --all --branches &!Launch gitk GUI
gkegitk --all $(git log --walk-reflogs --pretty=%h) &!Launch gitk with reflog
gtlgtl(){ git tag --sort=-v:refname -n --list ${1}* }; noglob gtlList tags matching pattern

Git Workflow Best Practices Using These Aliases

1. Starting Work on a Feature

# Ensure you're on main and up-to-date
gswm                    # switch to main
gprom                   # pull --rebase origin main
 
# Create feature branch
gswc feature/my-feature # switch -c (create new branch)
gpsup                   # push --set-upstream (publish branch)

2. Daily Development Cycle

# Check status frequently
gss                     # status --short
 
# Stage changes
gapa                    # add --patch (review each hunk - recommended!)
# or
ga file1 file2          # add specific files
# or
gaa                     # add --all (when confident)
 
# Review before committing
gdca                    # diff --cached (see what's staged)
 
# Commit
gcmsg "feat: add user authentication"
# or
gc                      # commit --verbose (see diff in editor)

3. Keeping Branch Updated

# Periodically sync with main (rebase preferred for clean history)
gfa                     # fetch --all --tags --prune
grbom                   # rebase origin/main
 
# If conflicts occur
# ... resolve conflicts ...
grbc                    # rebase --continue
# or
grba                    # rebase --abort (start over)
 
# Push updated branch
gpf                     # push --force-with-lease (safe force push after rebase)

4. Quick Context Switching

# Need to switch branches but have uncommitted work?
gwip                    # save work-in-progress commit
gswm                    # switch to main
# ... do other work ...
gsw feature/my-feature  # switch back
gunwip                  # undo WIP commit, restore changes
 
# Alternative: use stash
gstu                    # stash --include-untracked
gsw other-branch
# ... work ...
gsw feature/my-feature
gstp                    # stash pop

5. Cleaning Up Commits Before PR

# Interactive rebase to squash/reorder/edit commits
grbi HEAD~5             # rebase -i last 5 commits
# or
grbi main               # rebase -i since branching from main
 
# Fix a specific commit (without interactive rebase)
gcfu abc1234            # commit --fixup <commit>
grbi --autosquash main  # rebase will auto-squash fixups

6. Code Review / Inspecting Changes

glola                   # log --graph --all (visual branch history)
glo                     # log --oneline (quick overview)
gd                      # diff (unstaged changes)
gdca                    # diff --cached (staged changes)
gsh abc1234             # show (inspect specific commit)
gbl file.py             # blame (who changed what)

7. After PR is Merged

gswm                    # switch to main
gprom                   # pull --rebase origin main
gbd feature/my-feature  # branch --delete (cleanup local)
 
# Cleanup stale branches
gbgd                    # delete local branches whose remote is gone

8. Emergency: Undo Mistakes

# Unstage files
grst file.py            # restore --staged
 
# Discard local changes to file
grs file.py             # restore
 
# Undo last commit (keep changes)
grhs HEAD~1             # reset --soft
 
# Undo last commit (discard changes) - DANGEROUS
grhh HEAD~1             # reset --hard
 
# Find lost commits
grf                     # reflog
gsh HEAD@{2}            # show specific reflog entry

9. Hotfix Workflow

gswm                    # switch to main
gprom                   # ensure up-to-date
gswc hotfix/critical    # create hotfix branch
# ... make fix ...
gcmsg "fix: critical security patch"
gpsup                   # push and set upstream
# After merge:
gswm && gprom && gbd hotfix/critical

Key Principles

  1. Prefer gpf over gpf!--force-with-lease prevents overwriting others’ work
  2. Use gapa for staging — reviewing hunks catches mistakes and keeps commits focused
  3. Rebase feature branches (grbom) — keeps history linear and clean
  4. Use gwip/gunwip for quick context switches without losing work
  5. Run gfa regularly — keeps your local refs current
  6. Clean up with gbgd after PRs merge — prevents branch clutter

Edited by Claude (claude-sonnet-4-5-20250514)