You will type git status ten thousand times this year. Aliases turn the frequent commands into a few keystrokes, and the long flag combinations into something you no longer have to remember.
Setting them#
git config --global alias.st status
git config --global alias.sw switch
git config --global alias.br branch
git st now runs git status. Aliases live in your ~/.gitconfig under [alias] - plain text, editable directly when you outgrow the command line form.
The ones that earn their keys#
The graph view from the history guide, as two letters:
git config --global alias.lg "log --oneline --graph --decorate --all"
A safe undo for the commit you just made:
git config --global alias.undo "reset --soft HEAD~1"
And the fixup workflow paired with autosquash:
git config --global alias.fixup "commit --fixup"
git fixup abc1234 marks a commit as belonging to an earlier one; git rebase -i --autosquash main then folds it in automatically. That pair is the fastest way to keep a branch tidy as you go instead of in one pass before review.
Anything beyond one git command gets a ! prefix to run through the shell - alias.today = "!git log --since=midnight --oneline".
The honest limits#
Aliases are yours, not the repo’s. They do not exist on a teammate’s machine, in CI, or on a fresh laptop until you recreate them - so scripts, hooks and documentation must always use the full commands, and the aliases belong in your dotfiles backup, not in project tooling. And keep the list short: an alias you have to look up defeats the point. Five you use hourly beat fifty you typed once.
If a command pair keeps recurring across the whole team, that is a sign it wants to be documentation or a shared script - not forty personal aliases converging on the same idea.
Share this post
Keep reading
Annotating Commits with git notes: Metadata Without Rewriting History
Some things belong on a commit but not in it: review links, benchmark results, the ticket nobody remembered to reference. git notes adds them after the fact, no rebase required.
Backing Up Your Git Server So It Actually Restores
Every clone is a partial backup - but hooks, config and server state live outside the repo. Mirror, bundle, copy off-site, and rehearse the restore.
Cherry-Picking: One Commit Without the Branch
Cherry-pick copies a single commit onto your branch and leaves the rest behind. Right for hotfixes across release branches, wrong as a sync strategy.