I am lazy. But usefully lazy.
I believe that if you type the same long command more than three times a day, you should shorten it. Git commands can be verbose, but Git has a built-in aliasing system to fix that.
Introduction
Aliases allow you to map short commands to longer Git functions. You define them in your .gitconfig file (usually in your home directory) or by using the command line.
Here git config --global alias.co checkout allows you to type git co instead of git checkout.
Here are my top essential aliases.
The Essentials
Run these in your terminal to set them up:
# Basic navigation
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
# Unstaging files (undoing 'git add')
git config --global alias.unstage 'reset HEAD --'
Now, checking status is just git st. It saves milliseconds, but they add up to a feeling of fluidity.
The Visualizer: A Better Log
The default git log is a bit dry. I use an alias called lg that makes it look like a rainbow graph:
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
Try typing git lg after adding this. It shows you the branch tree, commit hash, relative time (“2 hours ago”), and author name in color. It’s beautiful.
The “Oops” Alias
Did you commit, but forgot to add a file? Or made a typo in the message?
git config --global alias.oops "commit --amend --no-edit"
Now, if you forget something:
git add forgotten_file.pygit oops
And it’s merged into the last commit like nothing happened.
Conclusion
Customizing your tools is a hallmark of a senior developer. It means you understand your workflow well enough to optimize it.
Take a few minutes to configure these aliases. Your fingers will thank you.
Did you like this post? Please let me know if you have any comments or suggestions.
Git posts that might be interesting for you