Git, CI/CD & GitOpsXXVI · Git ConfigurationGitConfig
Aliases — what they are, what they cost, and which ones to keep
What you'll learn
- Define a Git alias with git config alias.<name> and run it as git <name>
- List the common aliases for status, log, diff, and branch that production engineers use
- Recognise the maintenance cost of aliases that wrap flags Git may change across versions
- Choose the right scope for an alias (global for personal, local for repo-specific)
Prerequisites
Verified against Git 2.55.x teaching target; 2.40+ minimum · GitHub Actions continuous service; Aug 2026 documentation baseline · Argo CD v3.5.x teaching target; v3.0+ minimum · Flux v2.9.x · Sigstore Cosign v3.1.x · SLSA v1.2 · OCI Distribution Specification v1.1 · Git LFS v3.7.1 · Kubernetes (cross-course target) 1.36.x
A Git alias is a config key whose name starts with alias. and
whose value is a string Git expands and prepends to the command
line before execution. After git config alias.co checkout, the
command git co main is functionally identical to git checkout main. The alias is a textual substitution, not a function: Git
parses the expanded string as if the user had typed it. This is
the source of both the speed and the brittleness.
Defining an alias
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.st status
git config --global alias.lg "log --oneline --graph --decorate --all"
git config --global alias.unstage "reset HEAD --"
The first three are simple replacements. The fourth is a multi-
flag command; the string is stored verbatim and Git splits it on
whitespace before passing the pieces as the command and its
arguments. The fifth shows the common “alias as verb” pattern: a
single command that captures a workflow the engineer does often,
here “unstage a file that was git added by mistake”.
After defining these, the following are all valid:
git co main
git br -a
git st
git lg -n 20
git unstage path/to/file
Any arguments the engineer types after the alias are appended to
the expanded command, so git lg -n 20 becomes git log --oneline --graph --decorate --all -n 20.
flowchart LR
A["alias.lg = log --oneline --graph --decorate --all"] --> B["git lg -n 20"]
B --> C["git log --oneline --graph --decorate --all -n 20"]
Aliases worth keeping
A small set of aliases captures most of the productivity gain. The list below is the set the production engineers on the RunBook team have converged on; it errs on the side of well-known flags that are unlikely to change across Git versions:
st->statusfor the command that runs ten times a day.co->checkoutandbr->branchfor the two commands that dominate branch work.ci->commitfor the common case; the flag-specific flags (-a,--amend,-s) still get typed explicitly.lg->log --oneline --graph --decorate --allfor a one- line graph that shows every branch. The four flags are old and stable; this alias rarely breaks.unstage->reset HEAD --for the recurring mistake.last->log -1 HEADfor “what did I just commit”.diffc->diff --cachedfor “what is staged right now”.
Aliases that wrap flags Git may change (--first-parent was
introduced in 1.6.4, --graph formatting options have evolved
across versions) are aliases that need maintenance when the Git
binary is upgraded.
The maintenance cost
An alias is a string stored in a config file. The string is expanded by Git every time the alias is invoked, and the expanded command is parsed using the flags Git recognises in the running version. Three predictable failure modes:
- Flags that change meaning.
--decorateused to mean--decorate=shortin older versions and accepts values likefull,short,noin newer ones. An alias that pins--decorateto one value will not break, but an alias that wraps--format=%dmay render differently across versions. - Flags that are removed. Git occasionally renames or
removes flags. An alias that uses a removed flag is an alias
that fails with
error: unknown option. - Aliases that depend on shell features. An alias that uses
!to invoke a shell command (e.g.alias.visual = "!gitk") is portable only if the target binary exists on every machine the engineer runs the alias on.gitkis not installed by default on most server distributions.
The cost is paid by the engineer who maintains the alias, the
engineer who upgrades Git and finds the alias broken, and the
engineer who reads a teammate’s command (git lg) and has to
reconstruct what flags it expands to.
Where aliases should live
The scope decision is the same as for identity:
--globalfor personal aliases (st,co,br,lg). These follow the engineer across every repository.--localfor aliases that only make sense in a specific repository. Examples are aliases that wrap the repository’s CI command (alias.ci-test = testfor a project whosetesttarget is a long, project-specific command) or aliases that invoke repo-specific tooling.- Shared via
includeIf.gitdir:for team-wide aliases. The pattern is: keep the aliases in a file in a dotfiles repository, and pull them in conditionally per repository.
Production discipline
- Keep the alias set small and stable. Five to ten aliases that every engineer knows cover the productivity gain. A hundred aliases that only one engineer knows cover the same ground with a maintenance cost the team will not pay.
- Pin aliases to old, stable flags.
--oneline,--graph,--decorate,--cached,-1are stable; the newer--formatoptions and the experimental output flags are not. - Avoid shell-out aliases (
alias.x = "!command") in shared alias files. They depend on binaries that may not be installed on every machine and produce errors that look like Git errors. - Version-control shared aliases. Put them in a file in a
dotfiles repository or in the team’s
gitconfig-sharedand pull them in viaincludeIf. - Document non-trivial aliases. An alias that wraps a long command is one the engineer who reads the output will need to decode. A short comment in the shared config file is enough.
Quiz
Knowledge check · 4 questions
Q1. After `git config --global alias.lg 'log --oneline --graph --decorate --all'`, what does `git lg -n 20` execute?
Q2. An alias that wraps a flag Git later renames or removes is an alias that fails with `error: unknown option` when invoked, because the alias is a textual substitution that does not track flag changes across versions.
Q3. Name the three failure modes for Git aliases and explain which one is hardest to detect before production use.
Q4. Recommend a shared alias strategy for a team where every engineer currently maintains their own global aliases, and explain the trade-off.
A 12-engineer team has no shared alias file. Each engineer maintains a personal global config with 5-30 aliases. New hires copy a senior engineer's config as a starting point and diverge. A Git upgrade renames a flag several aliases depend on; four engineers' aliases break and the team does not know which ones. The team wants a single source of truth without forcing every engineer to use the same aliases.
Passing score: 75%. Answers are checked in this browser.