Learn AI Curriculum Cookbook

Foundations 4 min

Git — your AI safety net

Version control as 'undo for your whole project'. Essential when AI edits files.

Git is the "undo button" for your entire project. It tracks every change so you can review, revert, branch, or merge. When an AI tool is editing your code, git is what keeps you unafraid — you can always go back.

initial feature A fix bug you are here experiment branch next?

The five commands that cover 90% of daily git

CommandWhen you'd use it
git initOnce, in a new project, to start tracking
git status"What changed since my last save?"
git diff"Show me exactly what changed"
git commit -am "msg"Save a checkpoint of all tracked file changes
git restore ."Undo everything since my last commit"

The AI safety pattern

  1. Before letting an AI edit, commit what you have: git commit -am "before AI"
  2. Let the AI make its changes.
  3. Run git diff — read the actual changes, not the AI's summary.
  4. If you like it: git commit -am "AI: added X". If not: git restore . and try a different prompt.
Why this matters more for AI than for human edits. An AI can touch 20 files in 10 seconds. Without git, "undo" becomes "rewrite from memory". With git, "undo" is one command.

AI tools that are git-aware

  • aider auto-commits each AI edit — every change is its own undoable commit.
  • Cursor shows a diff in the editor before applying changes.
  • Claude Code respects .gitignore and runs git when you ask.
  • Cloud agents (Devin, Cowork, Copilot Workspace) return their work as pull requests — a git construct.

Going further (optional)

  • Branches — try a wild idea on a parallel timeline: git checkout -b experiment
  • GitHub / GitLab — a website that hosts your git repo and shows beautiful diffs
  • Pull requests (PRs) — propose changes for review before merging into main
What if I just deleted my AI's work and didn't have git?
Depends. Most editors keep a local history (VS Code's "Local History" panel; macOS Time Machine). But git is the only reliable undo across many files and many sessions. Add it to every project — even ones you think are throwaway.
Is git the same as GitHub?
No. Git is the version control tool that runs on your machine. GitHub (and GitLab, Bitbucket, Codeberg) are websites that host your git repos and add team features. You can use git without GitHub forever.