Lesson 2 of 5
Branches
A branch is just a movable pointer to a commit. git branch feature creates one, git checkout feature (or git switch) moves onto it.
Committing only advances the CURRENT branch — the others stay where they are. We model this with a dictionary name → commit index.
# git branch feature -> branches["feature"] = branches[current] # git checkout feature -> current = "feature" # git commit -> branches[current] = new_index
🎯 Exercise
The repo is on main at commit 0. Create the feature branch at the same point (branches["feature"] = 0), switch onto it (current = "feature"), then commit by advancing the current branch to commit 1 (branches[current] = 1). main must not move. Print current.
PRO lesson
This advanced chapter is part of CodeAge PRO. Unlock it to keep your adventure going.
Discover PRO →