How to Use Git Aliases to Save Time
If you type the same long Git commands every day, aliases can turn them into short, memorable commands. This guide explains how Git aliases work, shows useful examples for everyday tasks, and covers how to list, edit, and remove them without changing your repository history.
Practice Git workflows →What is a Git alias?
A Git alias is a shortcut for a Git subcommand. For example, you can define git st as a shorter way to run git status. Aliases are stored in Git configuration, either for your user account, for one repository, or at the system level.
User-level aliases are a convenient default because they are available in all your local repositories and are not committed with project files. Use repository-level configuration when an alias should be shared with a particular project and its collaborators.
How to create a Git alias
Use git config --global alias.<name> <command> to create a user-level alias. This example makes git st run git status:
git config --global alias.st status
git stThe --global option writes to your user Git configuration. To define an alias only in the current repository, omit --global and run the command from that repository. Git then saves it in the local repository configuration.
Useful Git alias examples
Start with a few commands you use often. These user-level examples provide a concise status, a decorated commit graph, and a shortcut for unstaging a file:
git config --global alias.st "status --short --branch"
git config --global alias.lg "log --oneline --graph --decorate --all"
git config --global alias.unstage "reset HEAD --"git stgives a compact status that includes the current branch.git lgshows a readable graph of commits and branch names. Since it includes--all, it can display branches beyond the current one.git unstage path/to/fileremoves a file from the staging area while keeping its working-tree changes. Reviewgit statusafterward to confirm the result.
Choose alias names you can remember and that do not obscure important behavior. Before relying on an alias in a team workflow, make sure you understand the full command it runs.
Where Git stores aliases and how to inspect them
Git keeps global configuration in your user config file and local configuration in the repository. You do not need to edit those files by hand; use Git to view the effective values:
git config --global --get-regexp '^alias\.'
git config --show-origin --get alias.stThe first command lists aliases configured globally. The second shows the value and the configuration file supplying a particular alias in the current repository. Local configuration can override global configuration with the same key.
How to change or remove an alias
Set the same alias again to change its command. To remove a global alias, unset it by name:
git config --global alias.st "status --branch"
git config --global --unset alias.stIf you created the alias locally, run git config --local --unset alias.<name> from that repository instead. Removing an alias only changes Git configuration; it does not affect commits or files.
Git alias FAQ
Can a Git alias accept arguments?
Yes. Git passes arguments you type after the alias to the underlying command. For example, after defining unstage above, git unstage README.md passes the path to reset HEAD --.
Can I create a shell command as a Git alias?
Git also supports shell-command aliases prefixed with !. Use them only when needed: they execute shell code and therefore require extra care with quoting, arguments, and untrusted input. For simple Git shortcuts, a regular alias is easier to understand and safer to maintain.