Git aliases allow you to create short names for frequently used Git commands. They can save typing time and make commonly used commands easier to remember.
git co as a shortcut
for git checkout or another command you frequently use.
A Git alias is a custom shortcut that represents another Git command.
For example, instead of typing:
git status
you can create an alias such as:
git st
The alias can make frequently used commands shorter.
Git commands can sometimes be long. Aliases can reduce repetitive typing.
The basic syntax for creating a Git alias is:
git config --global alias.alias-name "command"
The alias-name is the shortcut you want to create.
You can create a short alias for git status:
git config --global alias.st status
Now you can run:
git st
instead of:
git status
You can create a shortcut for the log command:
git config --global alias.lg "log --oneline"
Then use:
git lg
A compact log view can be created with an alias:
git config --global alias.last "log -1"
Now:
git last
shows the most recent commit.
The --global option stores the alias in your global Git
configuration.
git config --global alias.st status
This makes the alias available for your Git repositories on that computer.
You can create an alias only for the current repository by leaving out
--global.
git config alias.st status
This stores the setting in the repository's local Git configuration.
You can view configured Git settings using:
git config --list
You may see entries such as:
alias.st=status
alias.lg=log --oneline
Use git config --get to check a particular alias:
git config --get alias.st
The output may be:
status
You can create a short alias for git diff:
git config --global alias.df diff
Then use:
git df
A short branch alias can be created:
git config --global alias.br branch
Now:
git br
can be used to run the branch command.
You can create a shortcut for switching branches:
git config --global alias.sw switch
Then:
git sw main
Aliases can include command options.
git config --global alias.lg "log --oneline --graph"
Now:
git lg
runs the configured log command with its options.
A useful history alias can combine several log options:
git config --global alias.hist "log --oneline --graph --decorate --all"
You can then run:
git hist
To remove an alias from the global configuration:
git config --global --unset alias.st
The alias st will no longer be available globally.
If an alias was created for the current repository, remove it with:
git config --unset alias.st
You can create several aliases for commands used regularly:
git config --global alias.st status
git config --global alias.br branch
git config --global alias.sw switch
git config --global alias.df diff
git config --global alias.lg "log --oneline"
A Git alias is a shortcut defined in Git configuration. It does not create a new Git program or change the underlying Git command.
For example:
git st
can be configured to execute:
git status
Alias names are chosen by the user. Common short names include:
st → status
br → branch
sw → switch
df → diff
lg → log
ci → commit
co → checkout
Choose names that are easy for you and your workflow to remember.
A shortcut can be created for git commit:
git config --global alias.ci commit
Then:
git ci -m "Add login page"
runs the commit command with the message option.
You can create a shortcut for pulling changes:
git config --global alias.pl pull
Then use:
git pl
A push alias can be created:
git config --global alias.ps push
Now:
git ps
can run the push command.
Git aliases can also be configured to execute shell commands by starting the alias value with an exclamation mark.
git config --global alias.current '!git branch --show-current'
Then:
git current
can execute the configured shell command.
You can inspect configuration origins with:
git config --show-origin --get-regexp "^alias\."
This can help identify which Git configuration file contains an alias.
git config --global alias.st status
git config --global alias.br branch
git config --global alias.sw switch
git config --global alias.df diff
git config --global alias.ci commit
git config --global alias.lg "log --oneline"
git config --global alias.last "log -1"
These aliases can make common Git commands shorter.
# Create aliases
git config --global alias.st status
git config --global alias.br branch
git config --global alias.lg "log --oneline"
# Use aliases
git st
git br
git lg
This provides shorter commands for commonly used Git operations.
git config --get alias.st
git config --get alias.br
git config --get alias.lg
You can use these commands to verify that your aliases are configured correctly.
Git aliases provide convenient shortcuts for Git commands. They are especially useful for commands that you use frequently.
git config --global alias.st status
After creating the alias, you can use:
git st
Aliases can be global or repository-specific and can include command options.
git config is used to create aliases.--global creates an alias in the global Git configuration.--global, the alias can be repository-specific.git config --list can display Git configuration.git config --get alias.name checks a specific alias.git config --global --unset alias.name removes a global alias.Question: Which command creates a global alias named st for git status?