All Modules Why Git Core Loop Branches Review Diffs عربي

Version Control from Line One

Branches per milestone, clean commits, and reviewing every AI diff like a pull request.

Module 4 · Git as your safety net for fast, confident AI code.

Beginner Version Control Includes Lab ~45 min

What You'll Learn

  • Why version control matters more, not less, when an AI writes the code
  • The core Git loop and how to write commit messages worth reading
  • Keep main always working with a branch per milestone
  • Review every AI-generated diff like a pull request — with a checklist
  • Undo anything: restore, revert, and safe recovery
  • Hands-on lab: add a .gitignore, branch for M1, build the first slice, review the diff, and merge

Prerequisites: Module 3 — the snippet-vault repo with a committed SPEC.md.

Why Git Matters More With AI

An assistant can rewrite twenty files in ten seconds, sounding completely sure of itself. That speed is exactly why you need a safety net underneath it. Git gives you three superpowers that turn fast-and-risky into fast-and-safe:

SuperpowerWhat it means
A checkpointEvery commit is a save point you can return to. A bad AI edit is never permanent.
A magnifying glassgit diff shows exactly what changed, line by line — so you review before you trust.
A time machineSomething broke? git log and revert pinpoint and undo the change that did it.

You already started in Module 1

You've been committing since your first vibe. This module turns that into a discipline: small commits, branches, and diff review — the habits that make AI-speed development sustainable.

The Core Loop

Ninety percent of daily Git is five commands, in a rhythm you'll repeat all day:

CommandDoes
git statusWhat's changed and what's staged.
git diffThe exact line-by-line changes — read this before committing.
git add <file>Stage the changes you've reviewed and want to keep.
git commit -m "…"Save a checkpoint with a message.
git log --onelineThe history of checkpoints.

Commit messages worth reading

A good message says why, not just what. Short imperative subject, optional body for context:

Add create + list endpoints for snippets Implements milestone M1 from SPEC.md. In-memory store for now; a real database comes in the deploy module. No validation yet (M4).

Don't commit junk — use .gitignore

Generated and secret files should never enter Git. A .gitignore keeps node_modules/, build output (dist/), and especially .env secrets out of your history. Committing a secret once means it's in the history forever — prevention beats cleanup.

A Branch Per Milestone

Your main branch should always work. So you never build directly on it — you branch off for each milestone from SPEC.md, do the work there, then merge back when it's done and reviewed.

# start milestone M1 on its own branch git checkout -b feature/m1-create-list # ...build, review, commit on the branch... # merge the finished milestone back into main git checkout main git merge feature/m1-create-list

Why this pays off with AI

If the assistant takes a milestone in a bad direction, you just delete the branch — main is untouched. Branches make experiments cheap and mistakes disposable, which is exactly the freedom vibe coding needs.

Review Every AI Diff Like a PR

Treat the assistant as a teammate opening a pull request: you are the reviewer. Before you stage anything, run git diff and read every hunk against this checklist:

AskWhy
Does it match the spec?Only the story you're building — nothing extra.
Any secrets or keys?Never let credentials into a commit.
Any unrelated changes?AI often "helpfully" edits files you didn't mean to touch.
Do I understand every line?If you can't explain it, you can't maintain it — ask the assistant to explain, or simplify.
Is it small enough to review?If the diff is huge, split the task and try again.

"It ran" is not "I reviewed it"

Running the app proves it does something, not that it does the right thing safely. The diff review is where you catch the security hole, the hard-coded value, and the sneaky scope creep — before they're in your history.

Undo Anything

Because you commit often, recovery is easy. The three you'll actually use:

SituationCommand
Discard un-committed changes to a filegit restore <file>
Undo a bad commit, keeping history honestgit revert <hash>
Abandon a whole experimental branchgit checkout main then git branch -D <branch>

The confidence this buys

Knowing you can undo anything is what lets you move fast with an AI. You can accept a bold change, test it, and roll it back in one command if it's wrong. No fear, no lost work.

Practical Lab: Branch, Build a Slice, Review Like a PR

You'll set up a proper Git workflow and use it to build the first thin slice of milestone M1 from your spec — reviewing the AI's diff like a pull request before it lands.

What you need

Your snippet-vault repo from Module 3 (scaffold, context file, and SPEC.md), and your assistant.

1

Add a .gitignore

Ask the assistant to generate a .gitignore for a Node monorepo (ignore node_modules/, dist/, .env). Review it, then commit on main:

git add .gitignore git commit -m "Add .gitignore for node monorepo"
2

Branch for milestone M1

git checkout -b feature/m1-create-list
3

Ask for the first slice only

Point the assistant at your spec and keep the scope tiny:

Implement only M1 from SPEC.md: a Snippet type and two API endpoints — POST /snippets (create) and GET /snippets (list) — using an in-memory array for now (no database yet). No search, no delete, no UI. Small diff.
4

Review the diff like a PR

Before staging anything, read it against the checklist:

git status git diff

Matches the spec? No secrets? No unrelated files? Understand every line? Push back on anything that fails — ask the assistant to fix or explain before you accept.

5

Commit with a real message, then merge

git add . git commit -m "Add create + list endpoints for snippets (M1)" git checkout main git merge feature/m1-create-list
6

Reflect

In REFLECTION.md: paste your git log --oneline, and note one thing you caught while reading the diff that simply running the app would have hidden. Commit it.

What to hand in

Your snippet-vault repo. Self-check before submitting:

  • A .gitignore is committed (no node_modules/ in the repo)
  • M1 was built on a feature/ branch and merged into main
  • Commit messages say why, not just "update"
  • REFLECTION.md notes something the diff review caught

Mini Glossary

TermPlain meaning
CommitA saved checkpoint of your project at a point in time.
BranchA separate line of work that doesn't affect main until merged.
DiffThe exact lines added and removed by a change.
Pull request (PR)A proposed change others review before it merges — here, you review the AI's.
.gitignoreA list of files Git should never track (secrets, build output).
RevertA new commit that undoes an earlier one, keeping history intact.

Recap & What's Next

You now have

A clean Git workflow — .gitignore, a branch per milestone, small honest commits, and diff-review-as-PR — plus the first slice of M1 (create + list) built, reviewed, and merged to a working main.

Next up: Module 5 — Vibe-Coding the App. With the workflow in place, we run the real build loop — turning the rest of your milestones into working features, iterating fast, and knowing exactly when to take the wheel from the assistant.

Version Control from Line One

Objectives Why Git Core Loop Branches Review Diffs Undo Practical Lab Glossary Recap