Skip to content

Summary: Branches as parallel work surfaces

A branch is a movable pointer to a commit. Not a copy of the code. A label on the snapshot graph.

A ---- B ---- C ---- D
|\
| \
E F
^ ^
| |
feature main

Two 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.”

ActionCommand
Create branch and switch to itgit switch -c <name>
Switch to existing branchgit switch <name>
List local branchesgit branch
List all branches (incl. remote-tracking)git branch -a
Safe delete (refuses unmerged)git branch -d <name>
Force deletegit branch -D <name>

Older equivalents git checkout -b <name> and git checkout <name> still work and you’ll see them in tutorials.

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
  • 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

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.

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.