Lesson 44 of 51 ~16 min
Course progress
0%

Aliases and Shortcuts

Supercharge your Git productivity with custom aliases and shortcuts. Learn to create powerful command combinations and streamline your daily workflow.

Typing git status fifty times a day is like tying your shoelaces fifty times—you start craving shortcuts. Git lets you create aliases: shorthand commands that expand into full commands. With aliases, you transform Git from a verbose tool into a personal instrument tuned to your workflow. This chapter is about bending Git to your habits and speeding up daily work.


What Are Git Aliases?

Aliases are nicknames for commands. Instead of typing long sequences, you define short ones.

git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit

Now:

git st

is the same as:

git status

Visualization:

flowchart LR
  Short[git st] --> Expand[git status]

Creating Complex Aliases

Aliases can combine commands. Example: a log alias with graph and decoration:

git config --global alias.lg "log --oneline --graph --decorate --all"

Now git lg shows a beautiful overview of history.

Example output:

* a1b2c3d (HEAD -> main) fix: bug
| * e4f5g6h (feature) feat: add UI
|/
* 9z8y7x6 chore: init

Aliases with Parameters

Some commands allow parameters. Example: undo the last commit but keep changes staged:

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

Usage:

git unstage file.txt

Using External Commands

Aliases can run shell commands. Example:

git config --global alias.hist '!git log --graph --oneline --decorate --all'

Note the !, which tells Git to run a shell command.


Organizing Aliases

To view all aliases:

git config --get-regexp alias

They’re stored in ~/.gitconfig.

Example snippet:

[alias]
  st = status
  co = checkout
  br = branch
  ci = commit
  lg = log --oneline --graph --decorate --all

Productivity Boosters

Common Aliases

  • unstage: reset HEAD --
  • last: log -1 HEAD
  • amend: commit --amend
  • who: shortlog -sn

Advanced Aliases

  • today: log --since=midnight --oneline
  • rank: shortlog -sn --all --no-merges
  • cleanup: gc --prune=now --aggressive

Solo Workflow Example

As a solo dev, you alias logs to speed up debugging:

git config --global alias.lg "log --oneline --graph --decorate --all"

Now, instead of remembering flags, you type:

git lg

and instantly see the full DAG.


Team Workflow Example

On a team, standard aliases improve consistency. Everyone shares the same .gitconfig section in docs. This reduces friction: “run git lg” works for everyone.

Visualization:

flowchart TD
  DevA[Dev A using alias lg] --> Repo[Shared history view]
  DevB[Dev B using alias lg] --> Repo

Aliases vs Shell Shortcuts

Git aliases are stored in Git config, portable across repos. Shell aliases are faster but tied to environment. The best strategy: combine both. Use Git aliases for Git-specific commands, shell aliases for global tasks.


Think Different Mindset

Aliasing is personalization. Git isn’t rigid—it bends to you. Aliases teach efficiency and creativity. They whisper: tools aren’t fixed, they’re moldable. Don’t adapt to Git; make Git adapt to you.


Aliases shrink keystrokes and expand productivity. From st for status to lg for beautiful logs, they turn Git into a tool shaped by your hands. In the next chapter, we’ll explore team workflows—how multiple developers dance together using GitHub Flow, GitLab Flow, and trunk-based development.