learn git.
0/25 done
learn git/branches/course 19 of 25

git log --graph: see the family tree

Branches and merges, drawn in plain text.

6 min read·3 sections·2 tasks
the key idea

git log --oneline --graph draws the actual shape of your history — where lines split, where they rejoin.

01The command people put in aliases

Once branches enter your life, plain git log stops telling the whole story. It lists commits one by one — but hides which commit belonged to which branch, and where the lines of history split and rejoined. git log --oneline --graph adds a thin column of stars that draws the true shape: a fork where a branch was born, a rejoining where a merge landed.

Add --all and the picture widens to every branch, not just the one you are standing on — commits from other universes appear in their true place in the timeline. When anyone asks what the heck is going on with the branches, this is the command that answers.

[bash]· the history, drawn
git log --oneline --graph
git log --oneline --graph --all

02Reading the picture

Each line is one commit, newest first as always, prefixed by a star. The labels in brackets sit where the branch labels point: (HEAD -> main, feature) on one line means both labels share that commit — or, just as often, that two lines of history have just converged back into one.

Read a merge story top to bottom: a merge commit at the top, the two lines it united below it, and the fork point further down where they originally split. Every branch you ever make will appear in this picture as exactly that shape — a fork, some commits, a rejoin.

[bash]· a fork, two commits, and a merge — the whole shape of branching
*   f7e8d9a (HEAD -> main) Merge branch 'feature'
|\
* | 3a4b5c6 (main) work on main
* | 1a2b3c4 first
| * 9d8e7f6 (feature) work on feature
|/
* a1b2c3d the shared starting point
After every merge, look

Ten seconds of graph-gazing after each merge keeps your mental picture matched to git's reality. A matching mental model is what keeps everything after this feeling easy instead of scary.

03The habit worth building

This is the command to reach for at every moment of branch confusion: before a merge, to see what you are about to unite; after, to confirm it happened the way you expected; on a new team project, to understand the shape of how the work flows. The graph never lies and never changes — it is simply the album, drawn.

>>

Practice

A branch has already been merged. Look at the shape of it.

[practice]· a real terminal, safely simulated
practice terminal — everything here is simulated, nothing can break
type 'help' to see the commands this terminal understands
~/my-project (main) $
Your tasks0/2 done
  1. 01.Draw the graph with git log --oneline --graph.

    hint: Type: git log --oneline --graph

  2. 02.Try it with --all to see every branch.

    hint: Add --all to the same command.