git terminal graph with branch names

I have searched several times how to produce graph tree in terminal similar to Gitk or other GUI visualizers. Compiling the knowledge in this StackOverflow question together, I came up with the following command:

git log --graph --full-history --all --color --date=short --pretty=format:"%Cred%x09%h %Creset%ad%Cblue%d %Creset %s %C(bold)(%an)%Creset"

UPDATE: I added author name to the end of line in bold so that you can blame people quicker.

UPDATE 2: I changed the command to use Git color codes instead of ANSI to ease reading

This produces graph shown on the image.

(Unfortunately the %d placeholder does not support separate colors for local and remote branches, as --decorate itself does, which would be even better.)

To make it useful, I have aliased all of this for a much shorter command git tree, which can be done with the following git config line:

git config --global alias.tree 'log --graph --full-history --all --color --date=short --pretty=format:"%Cred%x09%h %Creset%ad%Cblue%d %Creset %s %C(bold)(%an)%Creset"'

NB! Notice the two sets of quatation marks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s