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.

Below is a snippet of the [alias] section of a .gitconfig file

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</tt> 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



Don't Panic!
Sometimes, you might have done something wrong in git. You think you've lost your commits, or something like that. Chances are, the information is still there--so the best course of action is to make an immediate backup, before you risk actually losing data. [alias] panic = !tar cvf ../git_panic.tar *