5.1

Git & Version Control

Experiment without fear using Git's safety net

πŸ”€ Tool ⏱️ ~20 minutes ⚑ Advanced

You're building a feature. Halfway through, you realize you've gone down the wrong path. Without Git, you're stuckβ€”manually undoing changes, hoping you remember what worked. With Git, you simply roll back to the last good state. That's the superpower of version control.

πŸ”€

Git Quick Reference

Essential Git commands for Claude Code workflows

πŸ“„ Preview PDF
Download PDF

πŸ€” Why Git Matters

Without Git:

  • You're afraid to experiment because you might break what works
  • You keep "backup" files: app-v1.js, app-v2-final.js, app-v2-final-REAL.js
  • You can't remember what changed between yesterday and today
  • Collaboration is copying files back and forth

With Git:

  • Experiment freelyβ€”you can always undo
  • Try risky ideas on branches without affecting your main code
  • See exactly what changed, when, and why
  • Collaborate with others (or future you) cleanly

✨ The Git Mindset

Git turns "don't break what works" into "try anything, roll back if it doesn't." That shift unlocks experimentation.

πŸ“‹ Git Basics for Claude Code

You don't need to master Git. You just need ~6 commands:

git init

Turn a folder into a Git repository (do this once per project)

git status

See what's changed since last save point

git add .

Stage all changes to be saved

git commit -m "message"

Save a snapshot with a description

git log --oneline

See history of save points

git checkout [commit]

Jump back to any previous save point

πŸš€ Your First Git Workflow

Here's how to add Git to your Claude Code projects:

🎯 Set Up Git for a Project

Navigate to your project:
cd ~/Documents/Projects/my-project
Initialize Git:
git init
This creates a hidden .git folder. Your project is now tracked.
Make your first save point:
git add .
git commit -m "Initial commit - project setup"
You've created checkpoint #1.
Work with Claude Code normally:
Build features, make changes, test things.
After each session or feature, save:
git add .
git commit -m "Added task completion feature"
Now you have checkpoint #2.
If something breaks, roll back:
git log --oneline (see checkpoints)
git checkout [commit-id] (jump back)
Your working code is restored.

βœ… Success Check

You'll know Git is working when: you can break things without worry, knowing you can always return to the last working version.

🌿 Branches: The Experimental Playground

Branches let you try ideas without touching your main code. Think of them as parallel universes for your project.

# Create a new branch for experimentation git checkout -b try-new-feature # Work on the feature with Claude Code # ...build and test... # If it works, merge it back: git checkout main git merge try-new-feature # If it doesn't work, just delete the branch: git branch -d try-new-feature

⚑ Pro Tip: Branch Per Feature

Create a new branch for each feature you build. If the feature works, merge it. If not, delete the branch. Your main code stays clean.

πŸ“– Complete Example: Git + Claude Code

Let's watch Git in action during a build session:

Project: To-do list app (working)
Goal: Add drag-and-drop reordering (risky!)

Step 1: Save Current State

git status β†’ Checks what's changed
git add .
git commit -m "Working todo list before drag-drop"
Checkpoint created. Safe to experiment.

Step 2: Create Experiment Branch

git checkout -b drag-drop-feature
Now in parallel universe. Main code untouched.

Step 3: Build with Claude Code

claude
Prompt: "Add drag-and-drop reordering to the todo list."
Claude builds the feature, testing as it goes.

Step 4: Test It

Opens browser, tries drag-drop.
Result: Works! But... deletes tasks accidentally. Bug!
Decision point: fix or abandon?

Step 5a: If Keeping (Fix It)

Prompt: "Fix: drag-drop deletes tasks. Should only reorder."
Claude fixes bug. Test again. Works!

git add .
git commit -m "Add drag-drop reordering"
git checkout main
git merge drag-drop-feature
Feature merged into main. Success!

Step 5b: If Abandoning (Roll Back)

Too buggy. Not worth the time.

git checkout main
git branch -d drag-drop-feature
Experiment deleted. Main code unchanged. Zero wasted cleanup.

✨ The Git Safety Net

Notice: no fear, no "save a backup first," no manually undoing changes. Git gave us permission to try something risky.

πŸ”„ Git in the Compound Loop

Git integrates beautifully with the 4-step loop:

Enhanced Loop with Git

Before PLAN: git checkout -b new-feature (create branch)
After WORK: git add . && git commit -m "Built feature" (save progress)
After ASSESS (if good): git checkout main && git merge new-feature (keep it)
After ASSESS (if bad): git checkout main && git branch -d new-feature (discard)
During COMPOUND: Update Claude.md, commit to main

⚠️ Common Git Mistakes

❌ Forgetting to commit

You work for 2 hours, then realize you never saved checkpoints. Commit after each meaningful chunk of work.

❌ Vague commit messages

"fixed stuff" tells future you nothing. Write: "Fixed: timer reset bug in startTimer()"

❌ Not using branches

Experimenting directly on main means you can't easily discard failed attempts. Branch first, merge if it works.

🎯 When You Don't Need Git

Git adds overhead. Skip it for:

  • Quick prototypes you'll throw away
  • Single-file experiments
  • Projects under 50 lines of code
  • When you're just learning the basics

Use Git when:

  • Projects have multiple files
  • You're building something you'll maintain
  • You want to try risky ideas safely
  • You're collaborating (even with future you)

πŸ“š Resources & Further Learning

πŸ’­ Pause & Reflect

Before moving on, take a moment to consider:

  • Have you ever lost work because you couldn't undo changes? Git prevents that.
  • What features would you try building if you knew you could easily roll back?
  • How would branches change your willingness to experiment?

🎯 Git Skills Acquired

You can now experiment without fear. Next: Advanced planning for complex features.

Topic 5.1 Complete β€’ Up Next: 5.2 – Advanced Planning & Research