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.
π€ 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:
Turn a folder into a Git repository (do this once per project)
See what's changed since last save point
Stage all changes to be saved
Save a snapshot with a description
See history of save points
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
cd ~/Documents/Projects/my-project
git initThis creates a hidden .git folder. Your project is now tracked.
git add .git commit -m "Initial commit - project setup"You've created checkpoint #1.
Build features, make changes, test things.
git add .git commit -m "Added task completion feature"Now you have checkpoint #2.
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.
β‘ 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!)
git status β Checks what's changed
git add .
git commit -m "Working todo list before drag-drop"
Checkpoint created. Safe to experiment.
git checkout -b drag-drop-feature
Now in parallel universe. Main code untouched.
claude
Prompt: "Add drag-and-drop reordering to the todo list."
Claude builds the feature, testing as it goes.
Opens browser, tries drag-drop.
Result: Works! But... deletes tasks accidentally. Bug!
Decision point: fix or abandon?
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!
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
git checkout -b new-feature (create branch)git add . && git commit -m "Built feature" (save progress)git checkout main && git merge new-feature (keep it)git checkout main && git branch -d new-feature (discard)β οΈ 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
- Learn Git Branching (Interactive) Visual, hands-on Git tutorial
- Oh Shit, Git!?! How to fix common Git mistakes
- Gitignore Templates What files NOT to track
π 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