Lesson 1 of 9 · about 15 minutes

What is a branch?

A sticky note on a commit — and the cheapest safety net you will ever own.

You will be able to explain what a branch really is, and use one in a simulator to keep main untouched while you experiment.

The problem branches solve

Picture this. You ask Claude Code to "refactor the cleaning code in clean.py and speed up the penguins notebook." It edits six files and makes three commits. The plots now look wrong, and every one of those commits went straight onto main, the branch your teammates (and your future self) trust. Undoing it means picking through history by hand.

A branch fixes this before it starts: the agent works beside main, not on it. If the work is good, you bring it in. If not, you throw the branch away and main never knew. GitHub describes branches as a way to "develop features, fix bugs, or safely experiment with new ideas in a contained area of your repository."2

A branch is just a pointer

You already know commits: snapshots of your project, each pointing back to the one before it. A branch is not a copy of your files. The Pro Git book puts it this way: a branch is "simply a lightweight movable pointer to one of these commits."1

load data explore plot species drop NaNs main HEAD → clean-data
Creating clean-data made a new pointer at "plot species." Committing on it moved only that pointer. main stayed put.

Three consequences matter for everything that follows:

On GitHub, new repositories call their default branch main.2 Plain git init on your laptop may still call it master until Git 3.0.3 They are the same idea. This course always says main.

Try it: protect main in the simulator

The simulator below is a tiny git that draws its commit graph. main already has two commits. Type the commands into the terminal line. Up-arrow recalls the previous command, and help lists what's supported. You only need two new commands:

$ git branch clean-data   # create a pointer here (does NOT move you)
$ git switch clean-data   # move HEAD onto it

Look at the graph after the last task. Your two commits sit on the clean-data lane, and the main label never moved. That is the whole safety net.

Check yourself

Answer from memory. Retrieval is what makes it stick.

What does Git actually do when you create a new branch?

A branch is a tiny file holding one commit hash. No files are copied, nothing goes to GitHub, and main is unaffected.

You are on clean-data and you make a commit. Which pointer moves?

HEAD names clean-data, so only that pointer advances to the new commit. That is exactly why agent work on a branch can't disturb main.

What does HEAD point to?

HEAD is "a pointer to the local branch you're currently on." Switching branches moves HEAD.

Why this matters for agentic coding

Claude Code can edit many files quickly. A branch per task gives that speed somewhere safe to land. In later lessons we'll call this an agent branch: the agent commits there, you review the result as a pull request, CI tests it, and only then does it reach main.

Read Pro Git §3.1, "Branches in a Nutshell". It has clear diagrams of exactly what you just did, and is the source this whole course builds on (about 10 minutes).
Anything fuzzy? Ask Claude: "Explain the difference between a branch and a commit using my penguins project as the example," or "What happens to HEAD when I switch branches?" Your teacher is one prompt away.

Sources

  1. Chacon & Straub, Pro Git, §3.1 Branches in a Nutshell.
  2. GitHub Docs, Branches (about branches; about the default branch).
  3. Git reference, git-init (default initial branch name).