Chapter 23: Version Control & Safe Experimentation
In 1998, Pixar accidentally deleted 90% of Toy Story 2. Their backup had silently failed. The film was saved only because one employee had a copy on her home computer. One command. Two years of work. Gone in seconds.
Every Claude Code session runs git commands behind the scenes. When you told it to "fix my authentication logic" last chapter, it ran git add, git commit, and git diff: commands you've never seen. It was protecting you without your knowledge.
What happens when it can't protect you? When you're working outside Claude Code: editing files manually, moving folders, collaborating with someone: there's no safety net. One bad change overwrites an hour of work. One accidental delete loses a week of progress.
This chapter teaches you the system your agent already uses. Not to memorize commands: your agent handles those. To understand the concepts so you can direct your agent's safety features intentionally, not accidentally.
Meet Sarah
Throughout this chapter, you'll follow Sarah. She's organizing a community fundraiser with her friend Maya. They share a project folder with budget spreadsheets, flyer designs, and volunteer lists. Sarah has never used version control. By the end of this chapter, she'll wonder how she ever worked without it.
Before You Start
You need three things before starting the lessons: a GitHub account, Git installed, and a one-time Git configuration. If you already have all three, skip to Lesson 1.
Git and GitHub are not the same thing. Git is a tool that runs on your computer and tracks changes to your files. GitHub is a website that stores copies of your Git projects in the cloud: if your laptop breaks, your work survives on GitHub. Git works without GitHub. GitHub doesn't work without Git. You'll use Git locally in Lessons 1-2, then connect it to GitHub in Lesson 3.
1. Create a GitHub Account
You'll use this in Lesson 3, but create it now: you'll need the email address in step 3 below.
- Visit github.com and click "Sign up"
- Choose a username carefully: this becomes your public portfolio URL:
github.com/yourname - Complete email verification
2. Install Git
Open your terminal and run:
git --version
If you see something like git version 2.39.0: skip to step 3.
macOS:
brew install git # Option 1: Homebrew (recommended)
xcode-select --install # Option 2: Xcode Command Line Tools
Windows: Download from git-scm.com/download/win, run installer with defaults, restart your terminal.
Linux:
sudo apt update && sudo apt install git # Ubuntu/Debian
sudo dnf install git # Fedora
sudo pacman -S git # Arch
After installing, close and reopen your terminal, then verify with git --version.
3. Tell Git Who You Are
Git labels every commit with your name and email. Use the same email you registered on GitHub: this links your commits to your GitHub profile.
git config --global user.name "Your Name"
git config --global user.email "your.github.email@example.com"
This isn't creating an account. It's a label that appears in your commit history. You only run this once.
Principles Applied
In The Seven Principles of General Agent Problem Solving, you learned the operational patterns that make AI collaboration reliable. This chapter puts four of them into practice: Git is where those principles become muscle memory.
| Principle | How It Applies in Git |
|---|---|
| Small, Reversible Decomposition | Commit small changes you can undo; branch for experiments |
| Verification as Core Step | Check status before and after every operation |
| Constraints and Safety | Branches isolate experiments; never push untested code |
| Observability | Git log shows exactly what changed, when, and why |
📚 Teaching Aid
What You'll Learn
By the end of this chapter, you'll be able to:
- Create project folders that track every change automatically
- Undo mistakes at any level, from a single edit to an entire experiment
- Test two ideas at once without risking your working project
- Back up your work to the cloud so a dead laptop doesn't mean lost work
- Review changes before combining them, even your own
- Follow three reusable patterns that professionals use daily
Lesson Flow
| Lesson | Title | Fast Visible Win |
|---|---|---|
| L01 | Git Foundations | Break a file, recover it in one command |
| L02 | Testing AI Safely with Branches | Watch a file disappear when you switch branches, and reappear when you switch back |
| L03 | Cloud Backup & Portfolio | Clone your project to a new folder and prove your backup works |
| L04 | Code Review, Pull Requests & Reusable Patterns | Create your first PR and name the three patterns professionals follow daily |
| Exercises | Exercises (Optional) | 15 hands-on challenges across 6 modules |
| Quiz | Chapter Quiz (Optional) | Test your understanding |
Chapter Contract
By chapter end, you should be able to answer these five questions:
- What is a commit, and why does it snapshot your entire project, not just one file?
- You made a bad edit, staged the wrong file, and committed a mistake. What's the correct undo for each?
- Why do branches let you test risky ideas without endangering your working project?
- What must you do before your first push to GitHub, and why can't you fix it after?
- What are the three patterns professionals follow daily, and when do you use each one?
After Chapter 23
When you finish this chapter, your working habits change:
- Commit before experimenting. You never let your agent touch working code without a snapshot first.
- Branch for anything risky. If you think "this might go wrong," you isolate the experiment.
- Push after meaningful work. Your laptop is an inconvenience to replace, not a catastrophe.
- Review before merging. Even your own code gets a second look before it reaches
main.
Start with Lesson 1: Git Foundations.