Sarah Lean š“ó §ó ¢
Posted on August 15, 2023
Typing long commands can get tiresome, this is where aliases can come in handy!
In this blog post Iāll share how you can set up aliases for your Git commands. Using aliases allows you to set up shortcuts that will make your life easier. There are two ways in which you can set up your aliases.
Set up aliases using the Git config command
You can set up your aliases using a command within your command line tool.
The format for the command is:
git config --global alias.<alias-name> '<git-command>'
In practice that means if you want to type git c instead of typing git checkout the alias you would configure is:
git config --global alias.c checkout
Set up aliases using the .gitconfig file
Another approach is to make modifications to the .gitconfig file. This is usually stored within your home directory, on my Windows machine it was stored under _C:\users\sarah\ _
Within this file create an alias section like below:
[alias]
# Shortcut for status
st = status
# Shortcut for checkout
co = checkout
# Shortcut for branch
b = branch
# Shortcut for help
h = help
# Shortcut for last commit
last = log -1 HEAD
# Shortcut to query log for altered files
l = log --stat
# Shortcut to query log and make it pretty
ld = log --graph --decorate --date=short
Deleting a Git alias
If you want to remove an alias you can delete the configuration from the .gitconfig file or you can use the following command:
git config --global --unset alias.<alias-name>
Check all aliases in Git
If you want to check which aliases are currently set within your configuration you can use the command:
git config --get-regexp '^alias\.'
Using Git aliases
Now that the aliases are set up you can now use them when you are within your command line tool. I can now use git l in lieu of git log āstat.
š” Itās important to remember, these aliases are only applicable to your local machine.
Posted on August 15, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 29, 2024