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.
| Alias | Expands to | Why it helps |
|---|---|---|
st | status -sb | Short, branch-aware status; one line per changed file. |
co | checkout | Muscle-memory shorthand; still useful for co -. |
sw | switch | Preferred over co for switching branches. |
br | branch -vv | Branch list with tracking info. |
cm | commit -m | Skip the editor when the message is short. |
ca | commit --amend --no-edit | Fold staged changes into the last commit without reopening the editor. |
lg | log --oneline --graph --all --decorate | Visual topology of all branches in one command. |
lp | log -p --follow | Full patch log for a file through renames. |
d | diff | Unstaged diff; faster to type. |
ds | diff --staged | Staged diff before committing. |
pop | stash pop | Shorthand; pairs with git stash. |
undo | reset --soft HEAD~1 | Soft-undo the last commit; changes stay staged. |
nuke | reset --hard HEAD | Discard all uncommitted changes. Dangerous; name it clearly. |
fixup | commit --fixup | Mark 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 --fixupLog format aliases
Richer log views for different audiences.
| Alias | Command | Output style |
|---|---|---|
ll | log --oneline -20 | Last 20 commits, terse. |
who | shortlog -sn --no-merges | Contributor commit count. |
last | log -1 HEAD | Full 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 --graphBranch and cleanup aliases
| Alias | Expands to | Use case |
|---|---|---|
gone | !git branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -d | Delete local branches whose remote is gone. |
fresh | fetch --all --prune | Fetch all remotes and prune stale tracking refs. |
main | switch main | Jump to main regardless of current branch. |
pub | push -u origin HEAD | Push 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 HEADShell aliases for git
Put these in ~/.zshrc or ~/.bashrc. They add the git prefix so you can type even less.
| Shell alias | Equivalent git command |
|---|---|
g | git |
gs | git status -sb |
ga | git add |
gd | git diff |
gds | git diff --staged |
gl | git lg |
gco | git switch |
gcm | git commit -m |
gp | git push |
gpf | git push --force-with-lease |
gpl | git 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.
| Command | Effect |
|---|---|
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 alias | List all current aliases. |
git config --global --unset alias.st | Remove 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
gis aliased togitandgsis defined as a shell alias,g stuses the git alias whilegsuses the shell alias. Keep the two namespaces distinct. commit --amend --no-edit(thecaalias) rewrites the last commit. Never use it after pushing to a shared branch.- The
gonealias deletes with-d(safe delete). Branches with unmerged commits survive. Switch to-Donly when you know what you are discarding. .gitconfigaliases are user-wide. For machine-specific aliases (different identity per machine), use[include]to source a machine-local config file.