Unit 8 · Vibe coding with guardrails
Commit before you let AI change your code
Commit before the AI starts, so there is a clean version to go back to. Git records nothing until you commit; if your only save point comes after the AI change, the bad change is already in it.
The mix-up
What people often think
“You commit once the AI has finished.”
What the tutor says
Then your only save point already contains the AI change. Commit first, so there is a clean version to return to.
How it works
A branch is cheap insurance. Make one before the experiment, read the diff while it is still on the side, and merge only what you have checked. Then main never sees the mess.
Asking the AI to undo its own changes is not the same. After a long session it may have lost track, and its “undo” is just more changes to check. A commit is a fact; a memory is a guess.
An example
git switch -c try-search-filter
git add -A && git commit -m "Before AI edit"
# ...let the tool work, then read the diff
git diff mainClose cousins of this mix-up
The tutor watches for these in the same lesson.
“Git saves my work automatically while the AI edits.”
Git only remembers what you commit. Without a commit before the AI starts, there is nothing clean to go back to.
“Git records every change automatically.”
Git records nothing until you commit. Your editor may have undo history, but it disappears when you close it.
“Branches are for when something has already gone wrong.”
A branch is cheap insurance. Make it before the experiment, and main never sees the mess.
“The AI can reliably undo the changes it made.”
The AI may have lost track after hours of edits, and its "undo" is just more changes you have to check. A commit is a fact; a memory is a guess.
Practise it with a tutor watching
Git as an undo button
Commit, branch, read the diff and revert, so a bad AI change costs you a minute instead of a day.
Free, no account needed.