---
title: "Git Aliases Cheatsheet"
slug: "git-aliases"
category: "cheatsheets"
tags: ["cheatsheets", "git", "aliases", "cli", "reference", "productivity", "shell"]
status: "stable"
last_updated: 2026-05-14
summary: "Useful git aliases (st, co, lg, cm, fixup) and shell aliases for common git workflows; how to set them up in .gitconfig and .zshrc."
related:
  [
    "[[coding/git]]",
    "[[coding/shell]]",
    "[[tooling/github-cli]]",
    "[[cheatsheets/git-commands]]",
    "[[cheatsheets/git-rebase]]",
    "[[cheatsheets/bash-one-liners]]",
    "[[cheatsheets/index|Cheatsheets]]",
  ]
---

## 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`. |

```ini
# ~/.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.

| 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` | Compact dated history with author. |

```ini
[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

| 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. |

```ini
[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 alias | Equivalent git command |
| --- | --- |
| `g` | `git` | Universal prefix shortener. |
| `gs` | `git status -sb` | Status anywhere. |
| `ga` | `git add` | Stage files. |
| `gd` | `git diff` | Unstaged diff. |
| `gds` | `git diff --staged` | Staged diff. |
| `gl` | `git lg` | Graph log (requires the `lg` alias above). |
| `gco` | `git switch` | Switch branches. |
| `gcm` | `git commit -m` | Commit with inline message. |
| `gp` | `git push` | Push. |
| `gpf` | `git push --force-with-lease` | Safer force-push. |
| `gpl` | `git pull --rebase` | Pull with rebase. |

```bash
# ~/.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 `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.

## Related

- [[coding/git]]
- [[coding/shell]]
- [[tooling/github-cli]]
- [[cheatsheets/git-commands]]
- [[cheatsheets/git-rebase]]
- [[cheatsheets/bash-one-liners]]
- [[cheatsheets/index|Cheatsheets]]
