Summary: Branches as parallel work surfaces
The one-sentence definition
Section titled “The one-sentence definition”A branch is a movable pointer to a commit. Not a copy of the code. A label on the snapshot graph.
The graph mental model
Section titled “The graph mental model”A ---- B ---- C ---- D |\ | \ E F ^ ^ | | feature mainTwo labels. Both started from D. Each moves forward independently as new commits land on each. HEAD is the pointer that says which label is “currently checked out.”
The essential commands
Section titled “The essential commands”| Action | Command |
|---|---|
| Create branch and switch to it | git switch -c <name> |
| Switch to existing branch | git switch <name> |
| List local branches | git branch |
| List all branches (incl. remote-tracking) | git branch -a |
| Safe delete (refuses unmerged) | git branch -d <name> |
| Force delete | git branch -D <name> |
Older equivalents git checkout -b <name> and git checkout <name> still work and you’ll see them in tutorials.
Why cheap branches matter
Section titled “Why cheap branches matter”In git, a branch is one filesystem write. In SVN/CVS, a branch was a server-side copy of the entire codebase. Cheap branches enabled:
- Branch-per-feature workflows
- Pull request reviews on every unit of work
- Free experimentation (failed experiments cost nothing)
- The entire modern git collaboration model
When to branch (the practical heuristic)
Section titled “When to branch (the practical heuristic)”- Branch for separable units of work
- Branch for experiments
- Branch when context-switching
- Branch for anything that will be reviewed
- Skip the branch for one-line typo fixes
- Skip the branch on solo prototypes with no collaborator
- Skip the branch for related commits that should land together
What you carry into L6
Section titled “What you carry into L6”You can create, switch, list, and delete branches. You understand HEAD. You see the graph.
L6 answers: “I have work on a branch. How do I propose to merge it back?” That is Pull Requests.
Voice anchor
Section titled “Voice anchor”Git stores snapshots. Every other command is just navigating those snapshots.
A branch is a label on the snapshot graph. Branch operations are label operations. The graph is the whole model.