A guide to Git Aliases

Join me as I look at explaining what Git aliases are, how you can create them and how to delete them as well.

A guide to Git Aliases
A guide to Git Aliases

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
Setting up a Git alias
Setting up a Git alias

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:


# 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>
Deleting a Git alias
Deleting a Git alias

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.