Optimising Git workflow with Git Aliases

29 April 2014
Git aliases is a good way to save few keystrokes and improve your productivity. So, in this post I will show you how to improve your productivity with git aliases.

Optimising Git workflow with Git Aliases


To customize git commands, you need to edit .gitconfig file located in your home directory(valid for *nix system, not sure about windows). So, without further ado let's get started.

Open .gitconfig file with your favorite text editor.

subl ~/.gitconfig


Now inside this file add the following lines


[alias]
    st = status
    aa = add -A
    cl = clone
    ci = commit
    df = diff
    br = branch
    co = checkout
    cob = checkout -b


Now you can use these aliases to save few keystrokes. For example you can use "git co feature_branch" instead of "git checkout feature_branch" to switch  to feature_branch, "git st" instead of "git status" to determine the current status of your working directory.

Now let's customize  one of  the most used git command i.e 'git log'.

lo = log


but this default log command is boring, so let's improve it.

lol = log --oneline


Much more use concise, but I'm not happy with formatting, so let's customize it even further.

lola = log --pretty=oneline --decorate --abbrev-commit -all


Looks good, but let's improve it even further with --graph option.

lola = --graph --pretty=oneline --decorate --abbrev-commit-all

git log ailas lola














Cool! You can even customize it even further with colors and more information like auther name, email, time etc.  Use this guide to customize it even further.


It would be nice to set an alias to list all the alias, so let's do it. Add following line in your .gitconfig file.

la = "!git config -l | grep alias | cut -c 7-"



Now running "git la" will list all of your git aliases. That's it. Are you using git aliases to improve your productivity? If so, then let me know what's your favorite git alias.


Reference: https://git.wiki.kernel.org/index.php/Aliases
Post a Comment