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.
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
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:
- Branches are nearly free. A branch is a small file holding a commit hash. Creating one is "as quick and simple as writing 41 bytes to a file."1 Make them freely, one per task.
- Committing moves only the current branch. Every other branch,
mainincluded, keeps pointing where it was. - Git always knows where you are. A special pointer called
HEADis "a pointer to the local branch you're currently on."1 The next commit moves whichever branchHEADnames.
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?
- Writes one small pointer file
- Copies every project file over
- Uploads a copy to GitHub
- Freezes main until you merge
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?
- Only clean-data moves forward
- Only main moves forward
- Both branches move forward
- Neither branch moves forward
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?
- the branch you are on
- the newest commit on GitHub
- the first commit ever made
- the branch named main always
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.
Sources
- Chacon & Straub, Pro Git, §3.1 Branches in a Nutshell.
- GitHub Docs, Branches (about branches; about the default branch).
- Git reference, git-init (default initial branch name).