Git tip: Beautiful colored and readable output

Git is a powerful tool that is very user friendly when used from the Command Line Interface (CLI). There is no need to add Graphical User Interface (GUI) tools to simplify or visualize the output. What can help to make the CLI output more usable is to enable colors and to allow for some command abbreviations (aliases). Below you see the output we get when we run our commands.

Git colored output

git-st-colored

As you can see, we configured the Git alias for “status”, so that it can be abbreviated with “st”. You can also see that the colored output has been enabled.

git-diff-colored

In Ubuntu colored diffs can be achieved be installed by using the “colordiff” tool. The “colordiff” tool is a replacement for the normal diff tool and can be used with the same arguments. It can be installed using “apt-get”, like this:

sudo apt-get install colordiff

However, Git does not require this because it has support for the colored diff built in.

git-lg

This is the most useful output. It is an enhanced Git “log” output that we alias as “lg”. By adding color it becomes dramatically more usable.

Instructions

We assume you have enabled the colored prompt in “.bashrc” by uncommenting the “force_color_prompt=yes” line as described in the previous Git post. Next you should add the following in your “~/.gitconfig” file:

	[alias]
		lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
		st = status
	[color]
		branch = auto
		diff = auto
		status = auto
	[color "branch"]
		current = yellow reverse
		local = yellow
		remote = green
	[color "diff"]
		meta = yellow bold
		frag = magenta bold
		old = red bold
		new = green bold
	[color "status"]
		added = yellow
		changed = green
		untracked = cyan

Save the file and try the commands. Enjoy!

3 Responses to “Git tip: Beautiful colored and readable output”

Leave a Reply