If you are a developer, chances are you type git dozens, if not hundreds, of times a day. Typing out long, repetitive commands like git commit -m or git log --oneline --graph isn't just a waste of time—it’s a drain on your focus. Every second spent wrestling with terminal syntax is a second taken away from actually solving problems. It is time to optimize your workflow with Git Aliases.
Git aliases allow you to create custom shortcuts for your most-used commands. By editing your global .gitconfig file, you can transform complex, multi-word commands into simple two-letter keystrokes. In this guide, I'll show you my personal setup that I've refined over years of repository management.
The "Keystroke Budget" Mentality
Think of your daily typing as a budget. Every keystroke has a cost in terms of physical strain and mental overhead. If you can reduce git checkout (12 keystrokes) to git co (6 keystrokes), you are saving 50% of the effort for one of your most frequent actions. Over a year, this adds up to thousands of saved movements. More importantly, it keeps your hands in sync with the speed of your thoughts.
How to Manage Your Git Aliases
There are two ways to add a Git alias. You can either use the command line directly or manually edit your global configuration file. I recommend editing the file directly because it allows you to see all your aliases at once and organize them logically.
To open your global config in your preferred editor, run:
git config --global -e
Once open, you'll see an [alias] section where you can start adding your own shortcuts.
1. st: The Fast Status
Checking the status of your working directory is the most common Git action. The standard git status output is verbose. We can make it cleaner. Instead of typing the full command, we map it to st.
# Add to your .gitconfig
st = status -s -b
The -s -b flags give you a "short" and "branch-focused" output. It shows you exactly what changed in a compact format without the "how-to-use-git" instructions that usually clutter the screen.
2. lg: The Beautiful Graphical Log
The default git log is practically unreadable for complex projects with multiple branches. This alias is my absolute favorite. It creates a color-coded, one-line graphical representation of your entire commit history, complete with author names and timestamps.
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
Type git lg and you'll suddenly see clear visualizations of where branches merge and who made which change. It is far superior to almost any GUI-based Git log viewer.
3. cm and aa: The Staging Workflow
Instead of git add . followed by git commit -m "message", I use two short aliases. aa adds everything (including untracked files), and cm handles the message. Together, they make committing code almost instantaneous.
aa = add --all
cm = commit -m
4. amend: The "Oops" Button
We've all done it: you commit your code, then realize you forgot to save one file or you made a typo in a comment. Instead of creating a second "fix typo" commit, use an amend alias.
amend = commit --amend --no-edit
This takes your current staged changes and merges them into the previous commit without prompting you to change the commit message. It keeps your history incredibly clean.
5. co and br: Branch Management
Switching (checkout) and listing (branch) are high-frequency tasks in any collaborative project. Shrinking them down to two letters each saves significant effort over a full workday.
co = checkout
br = branch -v
Advanced: Shell Aliases vs. Git Aliases
You might be wondering: "Why not just add alias gst='git status' to my .zshrc or .bashrc?" You should do that too! I use both. Shell aliases allow you to skip typing the word "git" entirely. However, Git aliases are more portable (they follow your Git config) and they allow you to use Git-specific flags which are sometimes harder to escape in shell aliases.
Frequently Asked Questions
Do these aliases work on Windows?
Yes. Git config is universal. Whether you are using Git Bash, PowerShell, or the Windows Command Prompt, these aliases will behave exactly the same way across all environments.
Can I share these aliases with my team?
You can! You can share your .gitconfig file or sections of it. Many developers keep their configuration in a public "Dotfiles" repository on GitHub so they can sync their shortcuts across different machines.
What if I forget what an alias does?
You can always view your list of aliases by running git config --get-regexp alias. But honestly, once you use git st ten times, you'll never forget what it does. Muscle memory is a powerful thing.
"The best programmer is the one who is lazy in all the right ways. Automate the boring, and focus on the brilliant."
The Bottom Line
By implementing these five aliases, you will significantly reduce the time spent typing terminal commands. It might take a few days to build the new muscle memory, but once you do, you will never want to go back to typing the full commands again. Optimize your environment, and the code will follow. Stay productive!
Disclaimer: "All content is for educational use only."