Skip to content
← All insights
Git & GitHub13 min read

Practical Git aliases: shorter commands without hidden surprises

How Git aliases are resolved, where configuration lives, which everyday aliases earn their place and why shortcuts should never conceal destructive repository operations.

An alias should remove repetition, not understanding

Git aliases give a shorter name to a Git subcommand or, with an exclamation mark, a shell command. A useful alias makes a familiar operation easier to type while leaving its effect recognisable.

Aliases are personal workflow tools unless a team deliberately shares and documents them. Build instructions, deployment steps and recovery procedures should not depend on an undocumented alias that only exists on one laptop.

Start with commands you already understand and repeat often. An alias is a poor way to learn a complicated rebase or hide a force push behind a friendly verb.

Create and inspect a simple aliasshell / Git
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch

git st
git config --global --get-regexp '^alias\.'

Configuration scope determines who sees it

A --global alias is stored in the user configuration and applies across repositories. A local alias is stored for one repository. System configuration is machine-wide and rarely the right home for personal shortcuts.

Use git config --show-origin to discover which file supplied a value. The same alias name can be overridden at a narrower scope, so checking only the global file can miss the command Git actually resolves.

Repository-local aliases are not automatically shared when someone clones the repository because .git/config is not versioned. If a project needs common scripts, keep ordinary executable commands or documented build-tool tasks in the repository instead.

See the active scope and originshell / Git
git config --global alias.lg "log --oneline --decorate --graph"
git config --local alias.review "diff --check"

git config --show-origin --get-regexp '^alias\.'

Git aliases are expanded as Git subcommands

Without an exclamation mark, the alias value is parsed as arguments following git. alias.last "log -1 HEAD" makes git last behave like git log -1 HEAD.

Aliases cannot redefine an existing Git command. Keep names easy to recall and avoid one-letter aliases whose meaning is only visible in old shell history.

Quoting occurs twice: once in the shell running git config and later when Git parses the stored alias. Inspect the resulting value after adding anything more complicated than a single subcommand.

A small set of readable aliasesshell / Git
git config --global alias.last "log -1 --stat"
git config --global alias.unstage "restore --staged"
git config --global alias.aliases "config --get-regexp ^alias\."

git last
git unstage path/to/file
git aliases

Make history useful for the question being asked

One log alias rarely covers every investigation. A compact graph helps with branch shape; a changed-file summary helps locate a relevant commit; a patch is needed when the exact behaviour matters.

Keep decorations and dates visible enough to orient the reader. Do not compress history into an unreadable format merely to fit more commits on screen.

Aliases can accept additional arguments. If lg expands to log --oneline --graph, git lg -- path/to/file adds the path restriction after the stored arguments.

Two views of repository historyshell / Git
git config --global alias.lg "log --graph --decorate --oneline --all"
git config --global alias.changed "log --stat --oneline"

git lg -- src/main/scala
git changed -10

Shell aliases are more powerful and more dangerous

A Git alias beginning with ! is executed by a shell from the repository’s top-level directory. It can use pipes, environment variables and several commands, but it also inherits shell quoting and portability concerns.

Use a shell function when arguments need to be handled deliberately. Positional parameters and quoting should be tested with spaces and unusual branch names. Once an alias becomes a script, a versioned script with tests and documentation is usually easier to maintain.

Never copy an opaque ! alias from the internet and run it in an important repository. Read every command first; the alias has the same filesystem and credential access as the Git process.

A shell alias with explicit argument handlinggitconfig
[alias]
  recent = !git branch --sort=-committerdate --format="%(committerdate:relative) %(refname:short)"
  files = "!f() { git diff --name-only "$1" "$2"; }; f"

# Usage:
# git recent
# git files main HEAD

Prefer safe inspection aliases

Status, log, diff, branch listing and configuration inspection are good candidates because they do not change repository history. Shortcuts for restore, reset, clean, force push and branch deletion deserve much more caution.

Do not alias a destructive command to a harmless-sounding word. Include the important mode in the alias name, keep confirmation where Git provides it and inspect the target before running it.

An alias that saves three characters but makes a rare dangerous operation easier to trigger has negative value. Optimise frequent, recoverable work first.

  • Good candidates: status, log, diff, show, branch listing
  • Use care: commit amendments, rebases and worktree changes
  • Avoid obscuring: hard resets, forced updates, clean and destructive deletion

Shell aliases and Git aliases solve different problems

A shell alias can shorten the initial git command and compose with other shell tools. A Git alias travels through Git configuration, appears in git config output and naturally accepts repository-relative Git arguments.

Use shell aliases for broader terminal workflows and Git aliases for Git vocabulary. Avoid defining the same name differently in both places; future debugging should not begin by guessing which expansion ran.

Aliases are not a replacement for learning the underlying command. Keep git help available and periodically remove shortcuts whose meaning is no longer obvious.

Remove or edit an alias cleanlyshell / Git
git config --global --unset alias.co
git config --global --edit

git help log
git help config

Treat a useful alias set as a small interface

A compact set of stable aliases becomes muscle memory. A catalogue of dozens becomes another command language to forget. Add one when repeated use demonstrates friction, and choose a name that still makes sense six months later.

If an alias is essential to a team workflow, promote the underlying operation into a repository script or build task and document it. Personal convenience should not become an invisible project dependency.

The best aliases preserve Git’s nouns and effects. They make the next command quicker without making the repository state harder to reason about.