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
This can be made into a git command via an entry your ~/.gitconfig
:
[alias]
graph = log --decorate --oneline --graph
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!).
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).
decorate
adds branch names and tags on the log entryoneline
cuts the message log to a single linegraph
makes branching visible through ASCII artSometimes 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.
Learn more about git-log(1) in the docs, there are many such gems hidden in there. A smidgeon of configuration makes git fun!