Warm-up · from “Selective staging and restoring changes”
Which state is affected by restore --staged?
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 glossarySay 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
- Base Ashared
- main: Btip
- feature: Ctip
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.
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.