Git Aliases: Save 30 Minutes Every Week

Git Aliases: Save 30 Minutes Every Week

If you type git checkout main or git commit -m twenty times a day, you are wasting your life.
Developers love automation, but they often forget to automate their most frequent tool: Git.

Today, we are setting up Git Aliases. These are short commands that expand into full commands. It’s like adding speed dial to your terminal.


1. How to Set an Alias

You don't need to edit config files manually. You can just run:

git config --global alias.co checkout

Now, instead of typing git checkout, you just type git co.
Magic.

2. The Essentials (Must-Haves)

Here are the 5 aliases that every developer needs. Run these in your terminal now:

Status (The most typed command)

git config --global alias.s status

Usage: git s

Checkout and Branch

git config --global alias.co checkout
git config --global alias.br branch

Usage: git co main, git br

Commit

git config --global alias.ci commit

Usage: git ci -m "Fix bug"

Unstage (The "Undo")

git config --global alias.unstage 'reset HEAD --'

Usage: git unstage file.txt (Removes from staging area)

3. The "Pretty Log" (Game Changer)

The default git log is ugly and hard to read.
Let’s make a graph that looks like a subway map.

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"

Now type git lg.
You will see a beautiful, colored history graph in your terminal. You'll never go back.


Frequently Asked Questions (FAQ)

Q: Why not just use a GUI like Git Kraken?

A: GUI tools are great for beginners, but they have limitations:

  • Speed: Clicking through menus is slower than typing git s in a terminal.
  • Automation: You can't script GUI actions. With aliases, you can chain commands together.
  • Remote Work: When SSH-ing into a server, you don't have a GUI. Terminal aliases work everywhere.

That said, many developers use both: GUI for visual diffs, aliases for daily commands.

Q: Will these aliases work on Mac/Linux?

A: Yes! Git aliases are cross-platform. They work identically on Windows (PowerShell/Git Bash), macOS, and Linux.

The only difference might be terminal color support. If git lg doesn't show colors on Windows, you may need to enable ANSI color support in your terminal settings.


Conclusion

It might seem lazy to type git s instead of git status.
But those seconds add up. More importantly, it reduces friction. The less resistance you have to using Git, the more often you will commit, and the safer your code will be.

Comments