Overview

Git aliases live in ~/.gitconfig under [alias]. Shell aliases belong in ~/.zshrc or ~/.bashrc. The two complement each other: git aliases shorten subcommands, shell aliases shorten the git prefix itself. This card lists the ones that pay off daily.

Core git aliases

Add these under [alias] in ~/.gitconfig.

AliasExpands toWhy it helps
ststatus -sbShort, branch-aware status; one line per changed file.
cocheckoutMuscle-memory shorthand; still useful for co -.
swswitchPreferred over co for switching branches.
brbranch -vvBranch list with tracking info.
cmcommit -mSkip the editor when the message is short.
cacommit --amend --no-editFold staged changes into the last commit without reopening the editor.
lglog --oneline --graph --all --decorateVisual topology of all branches in one command.
lplog -p --followFull patch log for a file through renames.
ddiffUnstaged diff; faster to type.
dsdiff --stagedStaged diff before committing.
popstash popShorthand; pairs with git stash.
undoreset --soft HEAD~1Soft-undo the last commit; changes stay staged.
nukereset --hard HEADDiscard all uncommitted changes. Dangerous; name it clearly.
fixupcommit --fixupMark a commit for autosquash; use with rebase --autosquash.
# ~/.gitconfig
[alias]
  st    = status -sb
  co    = checkout
  sw    = switch
  br    = branch -vv
  cm    = commit -m
  ca    = commit --amend --no-edit
  lg    = log --oneline --graph --all --decorate
  lp    = log -p --follow
  d     = diff
  ds    = diff --staged
  pop   = stash pop
  undo  = reset --soft HEAD~1
  nuke  = reset --hard HEAD
  fixup = commit --fixup

Log format aliases

Richer log views for different audiences.

AliasCommandOutput style
lllog --oneline -20Last 20 commits, terse.
whoshortlog -sn --no-mergesContributor commit count.
lastlog -1 HEADFull detail on the latest commit.
hist`log —pretty=format:“%h %ad%s%d [%an]” —date=short —graph`
[alias]
  ll   = log --oneline -20
  who  = shortlog -sn --no-merges
  last = log -1 HEAD
  hist = log --pretty=format:"%h %ad | %s%d [%an]" --date=short --graph

Branch and cleanup aliases

AliasExpands toUse case
gone!git branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -dDelete local branches whose remote is gone.
freshfetch --all --pruneFetch all remotes and prune stale tracking refs.
mainswitch mainJump to main regardless of current branch.
pubpush -u origin HEADPush current branch and set upstream in one step.
[alias]
  gone  = !git branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -d
  fresh = fetch --all --prune
  main  = switch main
  pub   = push -u origin HEAD

Shell aliases for git

Put these in ~/.zshrc or ~/.bashrc. They add the git prefix so you can type even less.

Shell aliasEquivalent git command
ggit
gsgit status -sb
gagit add
gdgit diff
gdsgit diff --staged
glgit lg
gcogit switch
gcmgit commit -m
gpgit push
gpfgit push --force-with-lease
gplgit pull --rebase
# ~/.zshrc
alias g='git'
alias gs='git status -sb'
alias ga='git add'
alias gd='git diff'
alias gds='git diff --staged'
alias gl='git lg'
alias gco='git switch'
alias gcm='git commit -m'
alias gp='git push'
alias gpf='git push --force-with-lease'
alias gpl='git pull --rebase'

Setting aliases via CLI

Add an alias without opening the config file manually.

CommandEffect
git config --global alias.st "status -sb"Add git st globally.
git config --local alias.st "status -sb"Add git st for the current repo only.
git config --global --list | grep aliasList all current aliases.
git config --global --unset alias.stRemove an alias.

Common gotchas

  • Git aliases that start with ! run shell commands. They run from the repo root, not from the current directory. Use $(git rev-parse --show-toplevel) when you need the working path.
  • Shell aliases shadowing git aliases cause confusion. If g is aliased to git and gs is defined as a shell alias, g st uses the git alias while gs uses the shell alias. Keep the two namespaces distinct.
  • commit --amend --no-edit (the ca alias) rewrites the last commit. Never use it after pushing to a shared branch.
  • The gone alias deletes with -d (safe delete). Branches with unmerged commits survive. Switch to -D only when you know what you are discarding.
  • .gitconfig aliases are user-wide. For machine-specific aliases (different identity per machine), use [include] to source a machine-local config file.