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
[alias] graph = log --decorate --oneline --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 --graph etc).
decorateadds branch names and tags on the log entry
onelinecuts the message log to a single line
graphmakes branching visible through ASCII art
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
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!