Git Config and Aliases — The 'git st' That Staged Everything
A developer aliased 'git st' to 'status' but their colleague's 'git st' ran 'add .'.
20+ years shipping production infrastructure and CI/CD at scale. Everything here is grounded in real deployments.
- ✓Basic programming fundamentals (variables, functions, control flow)
- ✓No prior devops experience needed — we start from first principles
Set user info: git config --global user.name 'Name'. Create aliases: git config --global alias.st status → git st runs status. Config levels: --system (all users), --global (your account), --local (current repo).
Git config is like a settings menu where you customize how Git behaves. Git aliases let you create keyboard shortcuts for your most-used commands. git config --global alias.co checkout means instead of typing git checkout, you type git co. It's like creating text shortcuts on your phone — 'omw' expands to 'on my way'. Git aliases expand to full commands.
Git aliases are the #1 productivity hack for daily Git users. A well-crafted set of aliases reduces common 5-word commands to 2-3 characters. git co instead of git checkout, git br instead of git branch, git lg for a pretty log output. But aliases come with a trap: if you share aliases (e.g., via a team .gitconfig), different developers may have different interpretations of the same alias. This guide covers the essential aliases, the three config levels and when to use each, and the incident where a shared alias file caused unexpected staging behavior.
Essential Git Aliases for Daily Use
The most productive aliases reduce common 3-6 word commands to 2-3 characters:
co = checkout—git co maininstead ofgit checkout mainbr = branch—git br -ainstead ofgit branch -aci = commit—git ci -m 'message'instead ofgit commit -m 'message'st = status—git stinstead ofgit statuslg = log --oneline --graph --decorate --all— pretty logunstage = reset HEAD --—git unstage fileto unstagelast = log -1 HEAD— show last commitamend = commit --amend --no-edit— quick amendundo = reset --soft HEAD~1— undo last commit
Set them: git config --global alias.lg "log --oneline --graph --decorate --all"
! to run a shell command instead of a git subcommand. Example: git config --global alias.remote '!git remote -v | head -5'. Or combine commands: git config --global alias.cleanup '!git branch --merged | grep -v "*" | xargs git branch -d'.~/.gitconfig (global) for personal shortcuts. Use --local (.git/config) for project-specific aliases (e.g., a monorepo with custom commands). Never commit a .gitconfig to the repo that auto-overwrites developer settings. Instead, document suggested aliases in CONTRIBUTING.md and let developers opt in. For teams using VS Code, the GitLens extension provides many visual shortcuts that reduce the need for CLI aliases.~/.gitconfig (global). Use ! for shell command aliases. Don't share aliases via committed config files — document suggestions and let developers opt in.The Shared Alias File That Made 'git st' Run 'git add .'
st = status and another later added st = add . thinking it was an unused shortcut. The second alias overwrote the first. The entire team's 'git st' started staging everything instead of showing status.st = status. 3. Developer B added st = add . thinking nobody was using 'st' for status. 4. The team's bootstrap script sourced the shared config. 5. 'git st' now ran 'git add .' — staging all files. 6. Developers ran 'git st' to check status before committing and unknowingly staged everything. 7. Sensitive files (.env, API keys) were staged and nearly committed.git config --global --unset alias.st to clear their local alias. 3. Set up an alias review process: any new alias must be discussed in the team channel. 4. Moved to a convention-based approach: git config --global alias.st status is standard, documented in the team README. 5. Added a CI check that warns if a shared .gitconfig has duplicate aliases.- Shared aliases must be carefully managed — duplicates silently overwrite.
- Use a documented convention for aliases.
- Less is more: start with 5 essential aliases.
- Per-repo aliases (local config) are safer for team adjustments.
git config --global alias.<shortcut> '<command>'git config --global --get-regexp alias--local config (stored in .git/config) for per-repo settingsKey takeaways
git config --global alias.<name> '<command>'--local for per-repo settings, --global for personal shortcuts20+ years shipping production infrastructure and CI/CD at scale. Everything here is grounded in real deployments.
That's Git. Mark it forged?
3 min read · try the examples if you haven't