Skip to content
rajin

13Commit graphs and movable references

core25–30 minHandbook pp. 31–32 Not started

Warm-up · from “Selective staging and restoring changes”

Which state is affected by restore --staged?

No notes: write what you remember, then check. Recalling before reading is what makes it stick.

The problem

A teammate creates a branch instantly in a repository with years of history. How can that be so cheap?

After this lesson you can

  • Draw a commit DAG.

  • Explain branch creation and movement.

  • Inspect refs independently of storage format.

Key terms

Full glossary

Say what each term means, then open it to check.

  • Ref · new in this lesson

    Name identifying an object; branch refs usually identify commits.

  • DAG · new in this lesson

    Directed acyclic graph; commit edges point to parents.

  • Commit · from lesson 7

    Object identifying a root tree, parent(s), metadata and message.

  • Reachability · preview, covered in lesson 27

    Whether an object can be reached by traversing links from roots.

Visual mental model

  1. Base Ashared
  2. main: Btip
  3. feature: Ctip
Arrows show parent links (from child to parent). Branch labels identify tips.

Build the mental model

Each commit links to its parent or parents, producing a directed acyclic graph (DAG). A branch is a movable ref to a commit, not a folder or a list of commits. Creating a branch adds a name to an existing commit. A new commit moves the currently checked-out branch; other branch refs stay where they are.

SimulationBranches are movable labels

A simplified model for building intuition. It does not read your sandbox; use the terminal for real behaviour.

Under the hood

In traditional SHA-1 repositories using loose refs, a branch ref may be a text file with 40 hex characters plus a newline. Refs can also be packed or stored in reftable; use git show-ref and git for-each-ref to inspect them. A commit is reachable from a ref if it is the ref target or can be reached by following parent links. Two branches may share most of their history.

Common mistake · important nuance

The graph's arrows represent parent links, pointing backward in history. Branch names are labels at tips, not containers.

Move between parts freely. Completion counts only what you verify and answer.