Simplify Your Workflow with Git Aliases
Sometimes, Git commands can get long and repetitive. For example, if you often run a command like:
git log --oneline --all --reverse
typing it again and again can be frustrating. Git Aliases solve this problem by letting you create your own shortcuts.
Why Use Git Aliases?
- Reduce typing for long commands you run frequently.
- Create meaningful shortcuts (like
git agfor "all logs"). - Apply aliases globally (across all repositories) or locally (per repo).
Example: Creating an Alias
Suppose we want to shorten this command:
git log --oneline --all --reverse
We can create an alias using:
git config --global alias.ag "log --oneline --all --reverse"
Here:
--global→ applies to all repositories on your system.alias.ag→ creates a shortcut namedag.- The command in quotes is the real Git command to run.
Using the Alias
Now instead of typing the long command, simply run:
git ag
Output will be the same as:
git log --oneline --all --reverse
Notes on Aliases
- Avoid underscores (
_) in alias names (Git doesn’t accept them). - You can create as many aliases as you like.
- Aliases only work with Git commands. For external shell commands, you’d need advanced configuration.
- If you don’t use
--global, the alias will only apply to the current repository.
Real-World Usage
In real projects, I personally keep 10+ Git aliases for everyday use. Some examples:
git config --global alias.st "status -s"
git config --global alias.co "checkout"
git config --global alias.br "branch"
git config --global alias.cm "commit -m"
These save huge amounts of typing when working with Git daily.
Summary
- Aliases let you shorten Git commands.
- Create them with
git config --global alias.<shortcut> "<command>". - Use them just like built-in Git commands.
- Great for saving time on frequently used commands.
Keep Learning 🚀
👉 Subscribe to Learning Ocean – Subscribers get coupon codes for my courses, early access to blogs and courses, and even exclusive YouTube videos.
👉 My YouTube Channel – More videos, more fun, and lots of learning!
👉 📺 Watch this topic in video form
Stay curious, keep coding, and let’s make learning fun together! 🎉