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. Below is a collection of useful aliases.

= How to set up an alias? =

In your  add an   section. Then each line is the  format.

Below is a snippet of the  section of a   file

= all together =

add
[alias] add = add -v
 * Example:

Always be verbose in response to add commands.

amend
[alias] amend = commit --amend -a
 * Example:

With Gerrit you may have to correct a patchset. This usually means editing files and then having to correct the previous commit message. The workflow would be something like:

$ git review -d 1234 // gerrit changeset id $ git add $ git commit --amend 

If you only changed files (not added new ones), the last two commands can be grouped by using.

br
[alias] br = branch
 * Example:

co
[alias] co = checkout
 * Example:

dc
[alias] dc = diff --cached
 * Example:

A plain  shows the diff between the (unstaged) working copy and the staged working copy. In most cases this is the same as the diff to the last committed revision.

However if you have already done  then those changes no longer show up in. Use  to create a diff between the already staged (but uncommitted) changes and the current HEAD.

di
[alias] di = diff
 * Example:

fetchall
[alias] fetchall = fetch -v --all
 * Example:



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

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



log-me
The author name is case-sensitive. [alias] log-me = log --author=hashar --pretty=format:'%h %cd %s' --date=short
 * Example:



log-nice
[alias] log-nice = log --graph --decorate --pretty=oneline --abbrev-commit
 * Example:



panic
[alias] panic = !tar cvf ../git_panic.tar * 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.

st
[alias] st = status
 * Example:

wdiff
[alias] wdiff   = diff --word-diff=plain
 * Example: