10 Git Aliases and Shortcuts to Speed Up Your Daily Workflow
Table of Contents
- Introduction
- How Git Aliases Work
- The 10 Aliases
- Bonus: Shell-Level Shortcuts
- Managing Your Aliases
- Conclusion
Introduction
If you use Git every day — and most engineers do — you're typing the same commands hundreds of times a week. git status, git checkout, git commit, over and over. Each one takes a few seconds. That adds up.
Git aliases let you define shorthand for any command, from simple abbreviations to complex multi-step workflows packed into a single keyword. They're trivial to set up, stored in your Git config, and once you start using them, you'll wonder how you ever worked without them.
Here are 10 aliases I've refined over years of daily use. They're not gimmicks — each one solves a real friction point in everyday development.
How Git Aliases Work
Git aliases are stored in your .gitconfig file (usually at ~/.gitconfig). You can set them via the command line or by editing the file directly.
Setting Aliases via Command Line
# Simple alias
git config --global alias.st status
# Now "git st" runs "git status"
Setting Aliases by Editing .gitconfig
# ~/.gitconfig
[alias]
st = status
co = checkout
br = branch
Shell Commands in Aliases
Prefix an alias with ! to run arbitrary shell commands instead of Git subcommands. This unlocks significantly more powerful aliases.
[alias]
# This runs a shell command, not a git subcommand
cleanup = !git branch --merged main | grep -v main | xargs git branch -d
With that out of the way, let's get to the good stuff.
The 10 Aliases
1. s — Quick Status
The command you run more than any other, compressed to a single character. The -sb flags give you a short, branch-aware output instead of the verbose default.
[alias]
s = status -sb
# Before: git status
# After: git s
# Output:
## feature/auth...origin/feature/auth
M src/auth.ts
?? src/config.local.ts
The short format shows your branch, tracking status, and modified files — everything you need at a glance without the noise.
2. lg — Beautiful Log
The default git log output is dense and hard to scan. This alias gives you a compact, color-coded, graph-decorated log that actually tells you what's going on.
[alias]
lg = log --graph --oneline --decorate --all
# Usage
git lg
# Output:
# * a1b2c3d (HEAD -> feature/auth) Add JWT validation
# * d4e5f6g Add login endpoint
# | * h7i8j9k (origin/main, main) Fix homepage typo
# |/
# * k0l1m2n Release v2.4.0
If you want even more detail — author names and relative dates — use this extended version:
[alias]
lga = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)' --all
3. cm — Commit with Message Inline
Skips opening the editor. You've already staged your changes — just type the message and go.
[alias]
cm = commit -m
# Before: git commit -m "fix: resolve null pointer in auth middleware"
# After: git cm "fix: resolve null pointer in auth middleware"
4. undo — Undo Last Commit (Keep Changes)
This is the alias you'll be most grateful for. It undoes your last commit but keeps all the changes staged and in your working directory — as if you never committed.
[alias]
undo = reset --soft HEAD~1
# Oops, committed too early or with the wrong message
git undo
# Your changes are back in staging, ready to recommit
Safe, non-destructive, and saves you from --amend gymnastics when you want to restructure a commit entirely.
5. save / pop — Quick Stash Shortcuts
Stashing is a two-step workflow you do constantly during context switches. These aliases make it feel instant.
[alias]
save = stash push -u -m
pop = stash pop
# Before: git stash push -u -m "WIP: dashboard layout"
# After: git save "WIP: dashboard layout"
# Before: git stash pop
# After: git pop
The -u flag in save includes untracked files automatically — one of the most common stash gotchas eliminated by default.
6. last — Show Last Commit
A quick sanity check after committing. Shows the full diff of your most recent commit.
[alias]
last = log -1 --stat
# Usage
git last
# Output:
# commit a1b2c3d (HEAD -> feature/auth)
# Author: You
# Date: Mon Mar 3 10:15:22 2026 +0400
#
# Add JWT validation middleware
#
# src/middleware/auth.ts | 42 +++++++++++++++++++
# src/routes/api.ts | 3 ++
# 2 files changed, 45 insertions(+)
7. amend — Quick Amend Without Editing Message
Forgot a file? Need to tweak something in the last commit? Stage the changes and amend without reopening the editor.
[alias]
amend = commit --amend --no-edit
# Stage the forgotten file, then:
git add src/forgotten-file.ts
git amend
# Last commit now includes the new file, same message
⚠️ WARNING: Don't amend commits that have been pushed to a shared branch. This rewrites history. If you've already pushed, use a new commit instead.
8. cleanup — Delete Merged Branches
After weeks of feature work, your local branch list becomes a graveyard of merged branches. This alias cleans them up in one shot.
[alias]
cleanup = !git branch --merged main | grep -v 'main\\|master\\|develop' | xargs -r git branch -d
# Usage
git cleanup
# Deleted branch feature/login (was a1b2c3d).
# Deleted branch fix/header-typo (was d4e5f6g).
# Deleted branch chore/update-deps (was h7i8j9k).
The grep -v protects your main branches from accidental deletion. The -r flag on xargs prevents errors when there's nothing to delete.
9. aliases — List All Your Aliases
Once you have more than a handful of aliases, you'll forget what's available. This meta-alias lists everything you've configured.
[alias]
aliases = config --get-regexp ^alias\\.
# Usage
git aliases
# alias.s status -sb
# alias.lg log --graph --oneline --decorate --all
# alias.cm commit -m
# alias.undo reset --soft HEAD~1
# ...
10. fresh — Sync Main and Prune in One Step
The first thing most engineers do when starting work: switch to main, pull the latest, and prune stale remote branches. This alias does all three.
[alias]
fresh = !git checkout main && git pull --rebase --prune && git cleanup
# Before:
# git checkout main
# git pull --rebase
# git fetch --prune
# git branch --merged main | grep -v main | xargs git branch -d
# After:
git fresh
# Switched to 'main', pulled latest, pruned remotes, cleaned up local branches
Note that this alias chains to the cleanup alias from #8. Aliases can call other aliases when prefixed with ! — that's what makes them composable.
Bonus: Shell-Level Shortcuts
Git aliases shorten what comes after git. Shell aliases can shorten git itself. Add these to your ~/.bashrc, ~/.zshrc, or equivalent:
# ~/.zshrc or ~/.bashrc
alias g="git"
alias gs="git s"
alias gc="git cm"
alias gp="git push"
alias gl="git pull --rebase"
alias gco="git checkout"
alias gb="git branch"
alias gd="git diff"
alias gf="git fresh"
With both layers combined, your workflow becomes remarkably fast:
# Full command: git status -sb
# Git alias: git s
# Shell + Git: gs
# Full command: git commit -m "fix: update retry logic"
# Git alias: git cm "fix: update retry logic"
# Shell + Git: gc "fix: update retry logic"
Some engineers go even further with tools like Oh My Zsh, which ships with a comprehensive Git plugin that provides dozens of pre-configured shortcuts out of the box.
Managing Your Aliases
The Complete .gitconfig Block
Here are all 10 aliases in one copy-pasteable block:
[alias]
# Basics
s = status -sb
cm = commit -m
amend = commit --amend --no-edit
last = log -1 --stat
# History
lg = log --graph --oneline --decorate --all
lga = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)' --all
# Undo and stash
undo = reset --soft HEAD~1
save = stash push -u -m
pop = stash pop
# Maintenance
cleanup = !git branch --merged main | grep -v 'main\\|master\\|develop' | xargs -r git branch -d
fresh = !git checkout main && git pull --rebase --prune && git cleanup
# Meta
aliases = config --get-regexp ^alias\\.
Sharing Aliases Across Teams
Your personal aliases live in ~/.gitconfig. But if your team wants shared aliases, you can include a shared config file:
# ~/.gitconfig
[include]
path = ~/team-gitconfig
Commit the shared file to your team's dotfiles repo, and everyone stays in sync.
When Not to Alias
A few things worth keeping explicit:
Destructive commands. I intentionally don't alias git reset --hard, git push --force, or git clean -fd. Typing them in full is a built-in moment of pause before doing something irreversible.
Rarely used commands. If you use a command once a month, an alias just adds cognitive load. Alias what you type daily.
Commands you're still learning. Typing the full command reinforces muscle memory and understanding. Once you know what it does without thinking, alias it.
Conclusion
Git aliases aren't about being clever — they're about removing friction from the commands you run most often. A few keystrokes saved per command, multiplied by hundreds of uses per week, adds up to real time and real focus preserved.
Start with the basics: s, cm, lg, and undo. Those four alone will change how your daily workflow feels. Add the rest as you find yourself repeating patterns. And when you build an alias that makes you think "I should have done this years ago" — that's the sweet spot.
Your terminal should feel fast. Make it fast.