Commits form a chain. Each new commit points back at the one before it. A branch is a name for a chain, pointing at its newest commit.
Every repository starts with one branch. Most teams call it main.
When you create a second branch, nothing is duplicated on disk. Git just adds a new name pointing at the same commit main is on. From then on, commits you make on the new branch move that name forward, and main stays where it was.
That's why branches are cheap. Making one takes a fraction of a second, so people make them for everything: a feature, a bug fix, an experiment they'll throw away.
Naming helps. fix-checkout-total says more than test2.
Quick check: You're on a branch called add-dark-mode and you make three commits. Has main changed?
## SPOKEN LINES
- Halfway through a rewrite in the live code, a customer reports the checkout page is gone. You needed a copy to work on while the original stayed clean.
- - BRANCH
- - A branch is a separate line of commits. The main branch is the version that works, and a new branch splits off from it so you can build for a week while main stays untouched.
- - Dark mode gets its own branch, a new checkout page gets its own branch, and a bug fix that takes 20 minutes gets one too.
- - So a branch is a separate line of development inside the same project. Tomorrow: Merge, how the branch gets back into main.
## NEXT
Day 23: Merge