List Git aliases
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Git aliases live in Git configuration, so listing them is really a configuration query problem. The most direct command is git config --get-regexp '^alias\.', which shows alias names and their configured command bodies.
List all aliases from the active config scope
Use this command first:
Typical output looks like this:
Git prints the config key followed by the alias value. The ^alias\. pattern limits the result to entries under the alias section.
Show only global aliases
If you want aliases from your user-level Git config only, add --global.
This is useful when you want to inspect aliases from ~/.gitconfig without mixing in repository-local settings.
Show the source file for each alias
When debugging why an alias exists, ask Git to show where each value came from.
That output includes the config file path, which helps when aliases are defined in multiple places.
Repository-local aliases can override expectations
A repository can define aliases in .git/config. Those aliases are available only inside that repository.
If a command behaves differently in one project than everywhere else, local config is the first place to inspect.
Inspect one alias directly when you know its name
If you only need to inspect one alias, query it directly instead of listing everything.
This is useful when a shell script, team setup guide, or terminal history mentions an alias and you want to see its exact expansion quickly.
It also avoids scanning unrelated aliases.
Read aliases directly from the config file if needed
You can also inspect the raw config sections.
The regular-expression form is usually cleaner, but --list can help when you want a broader picture of configuration at the same time.
Aliases may wrap shell commands
Some aliases start with !, which means Git runs them as shell commands rather than normal Git subcommands.
Listing aliases is especially important when shell aliases exist, because they can be much more powerful and much easier to misunderstand.
Use quoting carefully in scripts
If you are scripting alias inspection, keep the regular expression quoted so the shell does not interpret the backslash or caret unexpectedly.
That small detail avoids a surprising class of shell-specific failures.
Common Pitfalls
- Looking for aliases with
git aliaseven though Git has no built-in subcommand by that name. - Forgetting that aliases can exist in local, global, and system config scopes.
- Ignoring
--show-originand then not knowing which config file actually defined the alias. - Treating shell-style
!aliases like ordinary Git subcommand aliases. - Using
grepongit config --listwhen--get-regexpalready gives a cleaner filtered result.
Summary
- Use
git config --get-regexp '^alias\.'to list Git aliases. - Add
--globalor--localwhen you want a specific config scope. - Use
--show-originto see which file defined each alias. - Expect some aliases to be shell commands if they start with
!. - Inspect config scope before assuming an alias is missing or global.
Related reading
- List Git commits not pushed to the origin yet
- List of remotes for a Git repository?
- List of remotes for a Git repository?
- List submodules in a Git repository
- list tags contained by a branch
- Locking binary files using git version control system
- Logout and login as another user git bash
- Maintain git repo inside another git repo
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.