How To Use Git Alias To Speed Up The Development Process

Farhan Fuad Ronok
4 min readOct 31, 2021

--

Git aliases are used to create shortcuts of frequently used Git commands.

We simply need to add some well-formatted text in the .gitconfig file. and that’s it.

Now let’s discuss the steps:

In order to add git alias to your git configuration file (.gitconfig),
open a Command Prompt and type :

git version

Then you can see the Git version of your machine. If not, then there is a chance that git is not installed on your computer.

we can see that we have git installed and now we are ready to go,

Type:

git config --global --edit

You should see something like this:

The email and name will be different for everybody.

OK, let’s continue.

Now, we are going to add this block of text to our git config file.
You can just copy the whole block and paste it into the configuration file.

Linux users like me can do this with vim/Nano editor and widows users can edit the .gitconfig file with the editor of their preference.

After the copy+paste our git config file should look like this:

In order to verify that we have successfully added the text, we can run:

git config --global --list --show-origin

This command will show us all the configurations from the .gitconfig file. And we can see our alias has been added successfully to our .gitconfig file which is located in /home/ronok/.gitconfig directory on my computer.

So, enough with the setup. Let’s check how can we use the alias,

We can type :

git st

instead of:

git status

and git will show the current status of the directory.

Again, we can write:

git cob dev/newfeature

instead of:

git checkout -b dev/newfeature

And git will create and checkout to the ‘newfeature’ Branch.

Let’s go again,

let’s check out the last 20 git log, and for this, we can write:

git logg -20

instead of:

git log --all --decorate --oneline --graph --stat -20

and we should see something like this,

it’s showing :

  • commit hash with the commit message
  • The list of filenames with a number of changes per file.

let’s check out the last 5 git log with another command, and for this, we can write:

git le -5

instead of:

git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)(%ci) %C(bold blue)<%an>%Creset' -5

and we should see something like this.

it’s showing :

  • commit hash with the commit message
  • commit time in human-readable format
  • the author of the commit.

This is how we can use the git alias.

Bonus Tips

  • You can use any of your text editors to edit the .gitconfig file.
  • To learn and customize more you can check out official git log documentation (Link)
  • This article discusses one way to add a git alias but there are some other ways.

Thanks for reading and you can let me know if you have any questions or suggestions.

Connect with me via Linkedin Twitter

--

--

Farhan Fuad Ronok
Farhan Fuad Ronok

Written by Farhan Fuad Ronok

Software Engineer | write about backend, VOIP and DevOps Stuff.

No responses yet