Jiby's toolbox

Jb Doyon’s personal website

Git pretty graph

Posted on — Oct 6, 2019

Get a cool graph of commits from the command line! For newbies and experts alike, git is a bit hard to visualize. Here’s a handy git command to make understanding git easier.

git log --decorate --oneline --graph
Figure 1: Git graph of this repository

Figure 1: Git graph of this repository

This can be made into a git command via an entry your ~/.gitconfig:

	graph = log --decorate --oneline --graph
Code Snippet 1: Alias "graph" defined in ~/.gitconfig file

Invoke with

git graph

When this isn’t set on a machine (coworkers or servers I am just passing through), I usually remember it by the mnemonic device git DOG (like a puppy!).

Breaking it down

It’s useful to understand how/why this works. Since those are nothing more than command flags, try running each combination of these commands (eg: git log --decorate vs git log --graph etc).

When the tree gets big

Sometimes you want a larger picture of what’s happening. More flags exist for your enjoyment. Show all branches in one go:

git graph --all

This enables visualizing all branches, not just your current one. But sometimes you just want the gist of it: what branches, where did it branch off, where tags are, skipping the faff. For this, the --simplify-by-decoration flag is really helpful:

git graph --simplify-by-decoration

The flag hides commits that aren’t branches or tags. This makes long lines of commits “collapse” into one commit, with only the big moments of history shown instead of all of it.

Figure 2: Same graph with –simplified-by-decoration

Figure 2: Same graph with –simplified-by-decoration

Learn more about git-log(1) in the docs, there are many such gems hidden in there. A smidgeon of configuration makes git fun!