
Module 10 Lesson 1: Using aliases for speed
Stop typing long commands. Learn how to create custom Git aliases to turn complex commands into short, 2-character shortcuts that save you hours of typing every month.
Module 10 Lesson 1: Using aliases for speed
Do you find yourself typing git status 100 times a day? Or struggling to remember the exact syntax for a pretty graph log?
Git allows you to create Aliases—custom shortcuts for any command. In this lesson, we learn how to set them up and which ones the pros use every day.
1. How to Create an Alias
You use the git config command to map a shortcut to a full command.
# Set 'st' as a shortcut for 'status'
git config --global alias.st status
# Now you can just type:
git st
2. Essential Aliases for Every Developer
Here are the standard aliases used by most professional Git users. You should run these in your terminal right now!
The "Essentials"
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.cm "commit -m"
git config --global alias.st status
The "Pretty Log"
Instead of typing the long --graph --oneline flags every time, create a lg alias:
git config --global alias.lg "log --graph --oneline --all --decorate"
The "Unstage"
git config --global alias.unstage "restore --staged"
3. Editing Your Aliases Manually
If you want to see all your aliases or delete one, the easiest way is to open your global git config file in a text editor:
git config --global --edit
Look for the [alias] section. It should look like this:
[alias]
st = status
co = checkout
br = branch
lg = log --graph --oneline --all --decorate
graph LR
Input["User types: 'git st'"] --> Alias["Git checks [alias] section"]
Alias --> Execution["Git runs: 'git status'"]
Execution --> Output["Clean status output"]
Lesson Exercise
Goal: Build your custom productivity tool.
- Create an alias called
lastthat shows only the last commit details (log -1 HEAD). - Create an alias called
cob(for CheckOut Branch) that runsswitch -c. - Test both aliases in your practice repo.
- Open your
.gitconfigfile manually and verify that the aliases were added correctly.
Observation: You'll find that by reducing the "Friction" of typing, you actually use Git more effectively because it feels less like a chore.
Summary
In this lesson, we established:
- Aliases turn complex commands into short, memorable shortcuts.
git config --global alias.<name> "<command>"is the syntax.- The
lg(log graph) andst(status) aliases are industry staples. - You can manage all aliases in your
.gitconfigfile.
Next Lesson: Sometimes you need to find a needle in a haystack. Welcome to Lesson 2: Search and Interactive staging.