Save Hours with Custom Git Aliases
Git aliases turn multi-word commands into quick shortcuts, saving you hundreds of keystrokes every day.
What
Git aliases let you create shortcuts for commands you use frequently. You define them in your global .gitconfig file or per-repository config. Simple aliases map to existing commands, while more complex aliases can chain multiple commands or invoke shell scripts.
Why It Matters
Developers run Git commands dozens of times a day. Typing git checkout, git status, and git log --oneline --graph --all adds up fast. Aliases reduce friction, minimize typos, and let you build powerful custom workflows. They also make advanced commands more accessible to your team.
Example
# Create simple aliases
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
# Create a pretty log alias
git config --global alias.lg "log --oneline --graph --all --decorate"
# Create an alias to see last commit
git config --global alias.last "log -1 HEAD --stat"
# Now use them:
git co main # instead of git checkout main
git st # instead of git status
git lg # beautiful commit graphCommon Mistake
Creating aliases that shadow existing Git commands. For example, aliasing 'git log' to something else would override the built-in log command, causing confusion when the alias behaves differently than expected.
Quick Fix
Before creating an alias, check if the name already exists with git help <name>. Stick to abbreviations (co, br, ci, st) rather than overriding full command names. Review your aliases anytime with git config --global --list | grep alias.
Key Takeaways
- 1git config --global alias.<shortcut> '<command>' to create aliases
- 2Common aliases: co=checkout, br=branch, ci=commit, st=status
- 3Complex aliases can chain commands and use shell scripts
- 4Never shadow existing Git command names with aliases
- 5View all aliases: git config --global --list | grep alias
Was this tip helpful?
Help us improve the DevOpsPath daily collection