How to create alias for Git commands
As a Software Engineering, we normally interact with Git several times on a single day, writing commands in order to create a new work branch, send all the changes made to a remote repository, get all the changes done by the teammates to your local repository, etc.
Did you know that we can create some alias that abbreviates these commands? Let’s see how it works!
To customize git’s commands, we have the git config, that has three levels of configuration. They are:
git config --system
Related to machine configuration. Any change here will affect all the users and projects that exists on the environment.
git config --global
Related to single user configuration. Any change here will affect all projects under your user.
git config --local
Related to single project configuration. Any change here will affect the current project only, can only be used inside a git repository.
For this guide, we’ll work only with the global one. So here we go!
First of all, I really recommend you to run the following command that enables us to work with git config on our favorite code editor. In my case, I choose VS code.
git config --global core.editor code
Now, run the next command:
git config --global --edit
The VS code will open and we can start to edit our git configuration. Note that we already have some configs set, the user name, email and the one that we’ve just created.

To start the alias creation, we have to add a new section, on the same level as [user] and [core], named [alias]. That’s how my .gitconfig looks like:

As you can see, I added some commands that I usually use along the days. Important to say that all the commands must start with “!” on the .gitconfig file. Let’s make a quick overview on each of them:
Command: git add .
Alias: git a
Stages all the current changes, making them able to be commited.
Command: git commit --amend --no-edit
Alias: git amend
Adds all the staged changes to the last commit without change its message.
Command: git commit -m
Alias: git c
Creates a new commit with a message to describe it.
Command: git checkout
Alias: git co
Changes to a specific existing work branch.
Command: git log --pretty=format: '%h%C(green)%d %C(white)%s - %C(red)%cn'
Alias: git l
Shows the git commit history for the current branch. Here we have some modifiers that add colors and personalize what will be shown. You can see more here
Command: git status -s
Alias: git s
Shows the status about current changes.
You can create alias for all git commands that you desire, adding modifiers found on git’s docs. All the commands work on both way, with and without using alias.
I created an empty git repository to show all of them working as you can see below:

This is a simple thing that helps a lot! Hope you enjoy it! :D