Aliases that pay rent
The first ten Git aliases everyone reaches for cover the basics: st, co, br, ci. The next layer is where productivity really compounds - aliases for the multi-step workflows you do dozens of times per day. This collection focuses on those.
Logging
[alias]
l = log --oneline --decorate -20
ll = log --oneline --decorate --graph --all
lg = log --graph --pretty=format:'%C(yellow)%h%Creset %C(cyan)%an%Creset %s %C(green)(%cr)%Creset %C(red)%d%Creset'
recent = "log --pretty=format:'%C(yellow)%h%Creset %s %C(green)(%cr)%Creset' --date=relative -10"
Status and diffing
[alias]
s = status -sb
d = diff
dc = diff --cached
dw = diff --word-diff
ds = diff --stat
df = "!git diff --color $@ | diff-so-fancy"
Branch management
[alias]
br = branch
brd = branch -d
new = checkout -b
sw = switch
swc = switch -c
recent-branches = "for-each-ref --count=10 --sort=-committerdate refs/heads/ --format='%(refname:short)'"
gone = "!git fetch --prune && git branch -vv | awk '/: gone]/{print $1}' | xargs -r git branch -D"
Sync workflows
[alias]
sync = "!git fetch --all --prune && git pull --rebase"
update = "!git checkout main && git pull && git checkout - && git rebase main"
publish = "!git push -u origin $(git symbolic-ref --short HEAD)"
unpublish = "!git push origin --delete $(git symbolic-ref --short HEAD)"
Commit shortcuts
[alias]
amend = commit --amend --no-edit
reword = commit --amend
wip = "!git add -A && git commit -m 'WIP'"
unwip = reset --soft HEAD~1
save = "!f() { git add -A && git commit -m \"savepoint: ${1:-$(date)}\"; }; f"
Stash helpers
[alias]
ss = stash save
sp = stash pop
sl = stash list
sa = stash apply
Rebase helpers
[alias]
rb = rebase
rbi = rebase -i
rbc = rebase --continue
rba = rebase --abort
rbs = rebase --skip
fixup = "!f() { git commit --fixup $1; }; f"
autosquash = "rebase -i --autosquash"
History exploration
[alias]
who = "shortlog -sn --no-merges"
last = log -1 HEAD --stat
find = "!f() { git log --all --pretty=format:'%h %s' --grep=\"$1\"; }; f"
contains = "branch --contains"
first = "log --reverse --pretty=format:'%h %s' -1"
Cleanup
[alias]
cleanup = "!git fetch --prune && git branch --merged main | grep -v -E '^\\*|^\\s*(main|master|develop)$' | xargs -r git branch -d"
nuke = "!git reset --hard HEAD && git clean -fd"
prune-all = "!git fetch --all --prune && git gc --aggressive"
Loading aliases
# From a file
git config --global include.path ~/.gitconfig.aliases
This pattern keeps aliases in their own file for sharing across machines or teams. Commit it to a dotfiles repo and rebuild any machine in seconds.
Caveats
- Shell-prefixed aliases (
!) run in the repo root, not the cwd. - Aliases cannot override built-in commands.
- Test new aliases on throwaway repos before relying on them.
Customise relentlessly. The shell is yours; bend it to your habits.