The Directed Acyclic Graph

Updated

October 30, 2026

The Directed Acyclic Graph

After this page you can draw a tiny Git history as a graph and say what a branch is.

Snapshots with parents

A commit is a snapshot of the whole project at one instant, plus metadata (author, message, time) and a pointer to the commit that came before it — its parent.

Two commits in a row:

A  ←  B

B’s parent is A. Time flows left to right in this book’s diagrams; the parent pointer points backward, toward history.

A chain of commits is a directed acyclic graph (DAG): directed because each commit points at parents, acyclic because a commit cannot be its own ancestor.

A branch is a name

A branch is a movable name for one commit. main is a file that contains a hash. When you commit, Git writes a new snapshot whose parent is the current tip, then slides the name forward.

A  ←  B  ←  C     main

main now names C. A and B are still there. Nothing was overwritten.

A second line of work

Start a branch named feature while main is at C, then add two commits:

A  ←  B  ←  C          main
            ↑
            D  ←  E    feature

C has two children. Git is fine with that. A merge commit has two parents:

A  ←  B  ←  C  ←  M     main
            ↑     ↑
            D  ←  E     feature

M ties the two lines together. Rebase (chapter 9) copies D and E onto a new parent instead. New hashes, similar diffs. You will do that after first-repository muscle memory is in place.

Look at the graph

Once you have a repository (next chapter’s neighbor, chapter 3):

git log --oneline --graph --decorate --all

--decorate prints the names (main, HEAD, tags) next to the commits they point at. The graph is the truth. Commands add objects and move names. If you hold the graph, reset, rebase, and reflog stop feeling like magic.