What is a Git alias, and why would you set one up?

Last updated 6 July 2026

A Git alias is a shortcut you define for a longer Git command (or combination of commands), saving typing and standardizing complex workflows. They're stored in config under the [alias] section.

  • How they work: Set with git config --global alias.<name> <command>, then invoke as git <name>.

  • Why use them:

    • Shorten frequent commands (co for checkout).

    • Encapsulate complex flags you'd never remember (a pretty log format).

  • Shell escape: Prefix with ! to run an external shell command instead of a Git subcommand.

[lang:bash] git config --global alias.co checkout git config --global alias.lg "log --oneline --graph --decorate" # now: git co main git lg

  • https://git-scm.com/book/ms/v2/Git-Basics-Git-Aliases
  • https://git-scm.com/book/en/v2
  • https://www.atlassian.com/git/tutorials/git-alias
  • https://www.freecodecamp.org/news/how-to-simplify-your-git-commands-with-git-aliases/
  • https://www.geeksforgeeks.org/git/introduction-to-git-aliases/
  • https://www.eficode.com/insights/blog/10-levels-of-git-aliases-beginner-to-intermediate-concepts
  • https://heitorpb.github.io/bla/git-aliases/
  • https://www.git-tower.com/learn/git/faq/how-to-set-up-git-aliases
All Git interview questions