Get more out of your Git Client by using Git Alias.

Yasser Shaikh
yasser.dev
Published in
3 min readJul 24, 2020

I have always been one of those developers that have dreaded using Git CLI. So over the years I have used all kind of Git UI Clients, such as SourceTree, GitKraken, Git Extension (the one I use the most) to name a few. Recently I took out time to learn all about Git at Udemy to get my basics right, and got to know about this cool feature called — Git Alias which I am writing about today.

Git Alias

To simply put, Git Aliases are shorthand’s for your git commands.

Where should we use Git Alias?

Consider the following version of git log command, which returns a neatly stacked git history of my git repository.

git log --all --graph --decorate --oneline

Now this git log command has 4 arguments that we have to pass to it, in order to see the above log. It is very easy to forget the arguments, make a mistake with a typo and then bang your head on it and waste those precious minutes which you could have used for some actual development work.

Wouldn’t it be nice to just have a git history command to see the same output? This is where git alias can be useful.

Setting up a Git Alias

git config --global alias.history "log --all --graph --decorate --oneline"
  1. Using the command line, the below command has the –global arguments because we want this alias to be available regardless of the repository, that is we want it to be saved at the user level.
  2. Make sure to leave out the “git” part of the command

If everything is configured correctly, you should be able to see the same output now using the git history command.

Where is this configuration stored?

On windows, this configuration is stored in C:\users\username\.gitconfig file. You can open this file directly or use the command git config --global --edit to open this configuration in your default text editor. Here you will see our newly added “history” alias –

You can add more alias by updating directly updating this file.

What’s next?

People on the internet can get very creative with git alias, I found this cheat sheet (and some funny articles) which summarizes all commonly used git commands and shorthands which you can setup and use if you would like to.

How often do I use Git Alias?

I prefer to use the actual git commands and I use aliases only for the commands that are either too long or the ones which I tend to forget or do mistakes often with.

Cheers.

--

--

Yasser Shaikh
yasser.dev

Lead @ Agoda.com — Full stack Engineering. Gamer, Footballer, Bollywood Buff, Software Engineer, and @stackoverflow contributor. Mumbaikar.