I saw this post from @b0rk a while back, and figured I’d share my own favorite git aliases available at nonrational/dotfiles.

Alias Groups

All these aliases live in .gitconfig. Those that require multi-line shell operations delegate to .githelpers. h/t to Gary Bernhardt’s dotfiles for establishing this excellent pattern back in 2015.

Short Core Commands

There are ~6 commands that I use dozens of times a day, and I’ve shortened them to 1-2 characters each.

git st  # `status`
git ci  # `commit`
git aa  # `add --all`
git co  # `checkout`
git pp  # `push`
git f   # `fetch --tags --prune`

Pretty Logs

The value of log --graph has been diminished since I started using squashed merge commits, but it’s still useful when working with multiple nested branches.

git r
git l
git ra
git la
* 13f7f08      (5 months)   <github-actions[bot]>    (HEAD -> master, origin/master, origin/HEAD) Update .github/CODEOWNERS
*   fec2a08    (11 months)  <Sora Morimoto>          Merge pull request #43 from mainendra/master
|\
| * bef06f3    (11 months)  <Mainendra>              Cleanup
| * 4a91207    (11 months)  <Mainendra>              Combined conditions
| * 607e4c7    (11 months)  <Mainendra>              Added support for aarch64
* |   9172559  (11 months)  <Sora Morimoto>          Merge pull request #39 from danielbodart/master
|\ \
| |/
|/|
| * 7e24eda    (12 months)  <Daniel Bodart>          Add support for running in a windows bash prompt (i.e Git for Windows)
|/
| * f3cbb6c    (1 year)     <renovate[bot]>          (origin/renovate/configure) Add renovate.json
|/
*   0e14a50    (1 year)     <Sora Morimoto>          Merge pull request #35 from benperiton/patch-1
|\
| * 2a8f4be    (2 years)    <Ben Periton>            Update exec-env
* | ef5e9fb    (1 year)     <Sora Morimoto>          Delete .github/dependabot.yml
|/
*   87442fe    (2 years)    <Sora Morimoto>          Merge pull request #30 from asdf-community/dependabot/github_actions/actions/checkout-3
|\
| * bf496aa    (2 years)    <dependabot[bot]>        Bump actions/checkout from 2 to 3
|/
* 3b58b46      (2 years)    <Sora Morimoto>          Make formatting available under the test directory
* 6685b18      (3 years)    <Sora Morimoto>          More cleanup
*   79500fe    (3 years)    <Sora Morimoto>          Merge pull request #27 from kealjones-wk/patch-1

Working with PRs

git pro  # Pull Request Open - Open the current branch's PR in the browser, using `hub`.
git rio  # Rebase Interactive Origin - Rebase the current branch interactively against `origin/main`.

Working with Branches

git bcp  # Branch Copy - Copy the current branch branch name to the clipboard.
git bmx  # Branch Move Pattern - Apply a sed-like command to rename the current branch.
git buu  # Branch Unset Upstream - Unset the upstream for the current branch, if renaming a branch post-push.

More “Ignore” Options

Sometimes I want to preserve a change locally that I never intend to commit.

git disregard     # Ignore any changes to a tracked file.
git dissed        # List all files that have been disregarded.
git attend        # Stop ignoring changes to a file that was previously disregarded.

git is-it-just-me # Ignore an untracked file without adding it to `.gitignore`.

Keep Things Tidy

I often work on several branches at the same time and stale branches inevitably clutter up my local environment.

git broom            # Remove all local branches with my personal prefix that do not exist on origin.
git spring-cleaning  # Remove all branches with my personal prefix, both remote and local.
git everybody-out    # Remove all local branches that do not begin with my personal prefix.

Frequency Analysis

My top 50 git commands, with aliases explained.

# Print the top 50 most frequently used `git` commands
history \
  | awk '/[0-9] +git / {print $2,$3}' \
  | tr -d ';' \
  | sort | uniq -c | sort -r \
  | head -n50

My top 50 git commands, with aliases explained.

6388 git st      # Fewer characters to type than `status`.
1619 git ci      # Fewer characters to type than `commit`.
1545 git r       # Show the last 10 commits with `pretty_git_log`.
1507 git aa      # Stage all changes in the current directory and subdirectories.
1469 git co      # Fewer characters to type than `checkout`.
1277 git pp      # Fewer characters to type than `push`.
 932 git up      # Use `hub sync` to fetch and fast-forward *all* local branches, not just the current one.
 434 git f       # Fetch everything from origin, including tags, and prune deleted branches.
 287 git diff
 250 git reset
 241 git push
 211 git nuke    # Unstage and discard all changes, including deleting untracked files.
 177 git merge
 173 git add
 141 git rio     # Rebase the current branch interactively against origin/main.
 139 git branch
 132 git aww     # Stage all modified or added files matching a pattern.
 131 git stash
 126 git sww     # Switch to a branch matching a pattern.
  99 git pull
  90 git amend   # Fewer characters to type than `commit --amend`.
  86 git grep
  85 git dfo     # List only the files that differ between the current HEAD and origin/main.
  82 git lb      # List local branches with a relative modified date, recently modified first.
  81 git broom   # Remove all local branches that do not exist on origin.
  78 git ri      # Fewer characters to type than `rebase --interactive`.
  56 git rebase
  53 git show
  45 git l       # Show a paginated log with `pretty_git_log`.
  26 git brr     # List local branches, recently modified first.
  20 git df      # Fewer characters to type than `diff --name-only`.