Skip to main content

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.

  1. Visit github.com and click "Sign up"
  2. Choose a username carefully: this becomes your public portfolio URL: github.com/yourname
  3. 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.

PrincipleHow It Applies in Git
Small, Reversible DecompositionCommit small changes you can undo; branch for experiments
Verification as Core StepCheck status before and after every operation
Constraints and SafetyBranches isolate experiments; never push untested code
ObservabilityGit 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

LessonTitleFast Visible Win
L01Git FoundationsBreak a file, recover it in one command
L02Testing AI Safely with BranchesWatch a file disappear when you switch branches, and reappear when you switch back
L03Cloud Backup & PortfolioClone your project to a new folder and prove your backup works
L04Code Review, Pull Requests & Reusable PatternsCreate your first PR and name the three patterns professionals follow daily
ExercisesExercises (Optional)15 hands-on challenges across 6 modules
QuizChapter Quiz (Optional)Test your understanding

Chapter Contract

By chapter end, you should be able to answer these five questions:

  1. What is a commit, and why does it snapshot your entire project, not just one file?
  2. You made a bad edit, staged the wrong file, and committed a mistake. What's the correct undo for each?
  3. Why do branches let you test risky ideas without endangering your working project?
  4. What must you do before your first push to GitHub, and why can't you fix it after?
  5. 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:

  1. Commit before experimenting. You never let your agent touch working code without a snapshot first.
  2. Branch for anything risky. If you think "this might go wrong," you isolate the experiment.
  3. Push after meaningful work. Your laptop is an inconvenience to replace, not a catastrophe.
  4. Review before merging. Even your own code gets a second look before it reaches main.

Start with Lesson 1: Git Foundations.