Git aliases are custom shortcuts you create for commands you type frequently. Instead of typing out a full command every time, you define a short name for it and use that instead. They are stored in your Git configuration and are available in every repository on your machine.
Aliases do not change how Git works — they simply reduce the friction of using it every day.
Creating an Alias — git config --global alias
Aliases are set with git config using the alias. prefix followed by the shortcut name:
git config --global alias.<shortcut> '<command>'
The --global flag makes the alias available across all repositories on your machine.
Common Aliases Worth Setting Up
Shortening everyday commands
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
After these are set:
git st # Same as: git status
git co main # Same as: git checkout main
git br # Same as: git branch
git ci -m # Same as: git commit -m
These four are the most universally useful aliases — they are the commands you type dozens of times a day.
A more readable last commit
git config --global alias.last 'log -1 HEAD'
git last
# Shows the most recent commit in full detail
Creating a custom unstage command
Git has no built-in unstage command, which surprises many beginners. You can create one:
git config --global alias.unstage 'restore --staged'
Now these two are equivalent:
git unstage app.js
git restore --staged app.js
The alias version reads clearly and does not require you to remember the restore --staged syntax.
A compact, visual history
git config --global alias.lg 'log --oneline --graph --all --decorate'
git lg
# Shows a compact, branching history diagram in one line per commit
This is one of the most popular Git aliases in use. It gives you a bird's-eye view of your repository's history in a way that the default git log does not.
Show what has changed since the last commit
git config --global alias.changes 'diff --stat HEAD'
git changes
# Shows a file-level summary of what is different from the last commit
Aliases for Complex Commands
Aliases can hold any command Git accepts — including ones with multiple flags that would be impractical to type repeatedly:
# See branches with tracking info and ahead/behind counts
git config --global alias.branches 'branch -vv'
# List only merged branches
git config --global alias.merged 'branch --merged'
# List unmerged branches
git config --global alias.unmerged 'branch --no-merged'
# Verbose status in short format
git config --global alias.s 'status -s'
# Amend the last commit without editing the message
git config --global alias.amend 'commit --amend --no-edit'
Running External Commands
Aliases are not limited to Git subcommands. Prefixing the alias value with ! tells Git to run the value as a shell command instead:
git config --global alias.visual '!gitk'
git visual # Launches gitk, a graphical repository browser
This is useful for integrating external tools — git GUIs, custom scripts, or shell one-liners — directly into your Git workflow.
Viewing and Editing Aliases
Viewing all configured aliases
git config --global --get-regexp alias
alias.st status
alias.co checkout
alias.br branch
alias.ci commit
alias.last log -1 HEAD
alias.lg log --oneline --graph --all --decorate
Editing aliases directly in the config file
All aliases are stored in your ~/.gitconfig file. You can open and edit it directly:
git config --global --edit
The aliases section looks like this inside the file:
[alias]
st = status
co = checkout
br = branch
ci = commit
last = log -1 HEAD
lg = log --oneline --graph --all --decorate
unstage = restore --staged
Editing the file directly is often faster when you want to add or modify several aliases at once.
Removing an Alias
git config --global --unset alias.st
Or delete the line manually from ~/.gitconfig.
A Recommended Starter Set
Here is a complete set of aliases worth configuring on any new machine:
# Shorten daily commands
git config --global alias.st status
git config --global alias.s 'status -s'
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
# Useful shortcuts
git config --global alias.last 'log -1 HEAD'
git config --global alias.unstage 'restore --staged'
git config --global alias.amend 'commit --amend --no-edit'
# Visual history
git config --global alias.lg 'log --oneline --graph --all --decorate'
# Branch inspection
git config --global alias.branches 'branch -vv'
Summary
| Command | What It Does |
|---|---|
git config --global alias.<name> '<command>' | Creates a new alias |
git config --global --get-regexp alias | Lists all configured aliases |
git config --global --edit | Opens the config file to edit aliases directly |
git config --global --unset alias.<name> | Removes an alias |