Creating and Switching in One Step
git checkout -b spicy-experiments
Creates a new branch pointing at the current commit, and moves HEAD to it in the same command. From this point on, any commit lands on spicy-experiments, not master.
Committing Only on the Branch
# create ghost-pepper-wings.md
git add ghost-pepper-wings.md
git commit -m "Add ghost pepper chicken wings recipe"
This commit's parent is master's tip, but it exists only on spicy-experiments — master's own pointer has not moved at all.
Switching Back and Verifying
git checkout master
ls # ghost-pepper-wings.md is genuinely gone
git log --oneline --all --decorate --graph
--all shows every branch's history at once; the graph makes it visible that spicy-experiments split off and master's own line never changed.
Fifteen real commits sit on master right now — the whole cookie, pasta, soup, and waffle collection, exactly as it should be. You have an idea for a ghost pepper wings recipe, and it genuinely does not belong mixed in with the tested, working collection while you are still figuring it out.
A branch is the real answer: a new, independent line of commits starting from wherever master currently is. Commits made on the branch exist only there until you decide otherwise — master is never touched by them, confirmed directly in this lab rather than taken on faith.
Branch
A movable pointer to a specific commit. Creating one costs nothing and copies nothing — it is genuinely just a new named pointer, confirmed directly in the next lesson by looking at exactly what a branch is made of on disk.
HEAD
Git's record of which branch (and therefore which commit) you are currently on. git checkout -b spicy-experiments moves HEAD to point at the new branch — every commit from then on advances that branch specifically, not whichever branch HEAD pointed at before.
Takeaways
- git checkout -b <name> creates a branch and switches to it in one real command
- A commit's parent is whatever HEAD points at the moment git commit runs — nothing more
- Switching branches genuinely changes the files in the working directory to match that branch's own tip
- git log --oneline --all --decorate --graph shows every branch's real history and where they diverge, in one view
- Creating a branch costs nothing — it is a new pointer, not a copy of the whole project