Lesson Completion
Back to course

Aliases

Beginner
7 minutes4.7Git

The Hook (The "Byte-Sized" Intro)

git log --oneline --graph --all --decorate is 42 characters. With an alias, it becomes git lg. Aliases turn long, hard-to-remember commands into short, memorable ones. Top developers have 10-20 aliases that save them thousands of keystrokes per day. Here are the ones worth setting up.

📖 What are Aliases?

Git aliases are custom shortcuts stored in your config that map short names to longer commands.

Conceptual Clarity

Essential aliases:

AliasExpands ToPurpose
ststatus -sbShort status
cocheckoutSwitch branches
brbranchList branches
cicommitCreate commit
lglog --oneline --graph --all --decoratePretty graph
unstagereset HEAD --Unstage files
lastlog -1 HEAD --statLast commit
amendcommit --amend --no-editQuick amend

Alias types:

TypeSyntaxExample
Simplegit config --global alias.co checkoutgit co
With flagsgit config --global alias.lg "log --oneline --graph"git lg
Shell commandgit config --global alias.cleanup '!git branch --merged | grep -v main | xargs git branch -d'git cleanup

Real-Life Analogy

Aliases are keyboard shortcuts for Git. Just like Ctrl+C copies text instead of typing Edit → Copy, git co checks out a branch instead of typing git checkout.

Visual Architecture

flowchart LR SHORT["git lg"] -->|"alias"| LONG["git log --oneline<br/>--graph --all --decorate"] style SHORT fill:#1b2d1b,stroke:#53d8fb,color:#53d8fb style LONG fill:#1a1a2e,stroke:#ffd700,color:#ffd700

Why It Matters

  • Speed: Save thousands of keystrokes daily.
  • Consistency: Always use the right flags without remembering them.
  • Complex commands: Wrap multi-step operations in one alias.
  • Personalization: Customize Git to match your workflow.

Code

bash
# ─── Set up essential aliases ─── git config --global alias.st "status -sb" git config --global alias.co "checkout" git config --global alias.br "branch" git config --global alias.ci "commit" git config --global alias.lg "log --oneline --graph --all --decorate" git config --global alias.unstage "reset HEAD --" git config --global alias.last "log -1 HEAD --stat" git config --global alias.amend "commit --amend --no-edit" # ─── Shell aliases (prefix with !) ─── git config --global alias.cleanup '!git branch --merged | grep -v main | xargs git branch -d' # ─── Use them ─── git st # Short status git lg # Pretty graph git last # Last commit details git amend # Quick amend # ─── List all aliases ─── git config --get-regexp alias

Key Takeaways

  • Aliases map short names to long commands — set once, use forever.
  • Shell aliases (prefix !) can run arbitrary shell commands.
  • git config --get-regexp alias lists all your aliases.
  • Start with 5-8 essential aliases and add more as patterns emerge.

Interview Prep

  • Q: What are Git aliases and how do you create them? A: Aliases are custom shortcuts stored in Git config. Create them with git config --global alias.<name> "<command>". For example, alias.co checkout lets you type git co instead of git checkout.

  • Q: What is the difference between a regular alias and a shell alias? A: Regular aliases expand to Git commands. Shell aliases (prefixed with !) run arbitrary shell commands, enabling multi-step operations like !git branch --merged | xargs git branch -d.

  • Q: How do you list all configured aliases? A: git config --get-regexp alias shows all aliases and their expansions.

Topics Covered

Git ConfigurationProductivity

Tags

#git#aliases#config#productivity

Last Updated

2026-02-13