Git/aliases

Git is a powerfull tool with a lot of useful options. Did you know you can make alias for a command and a set of options ? You will no more have to write long shell one-liners.

How to set up an alias?
In your ~/.gitconfig add an [alias] section. Then each line is a &lt;tab&gt;key = value format.

Easy add and amend
With Gerrit as a middleware, you will often have to correct a patchset. This usually mean editing files and then having to correct the previous commit message. The workflow would be something like:

$ git add * $ git commit --amend

All of that can be replaced by the simpler git commit --amend -a. Lets just name it amend:

[alias] amend = commit --amend -a

Diff at the word level
[alias] wdiff   = diff --word-diff=plain

Fetch every remote
[alias] fetchall = fetch -v --all



In this case, both origin and gerrit are the same, good enough for the above screenshot.

What I have done recently ?
[alias] mylog   = log --author hashar --pretty=format:'%h %cd %s' --date=short



Fancy log and graph
[alias] lg = log --graph --pretty=format:'%Cred%h%Creset \ -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(cyan)<%an>%Creset' \ --abbrev-commit --date=relative