Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Version Control and Testing  ›  Lesson

Commit Before You Prompt

Master Version Control 12 minCommit a working, tested state before every AI change, and use a branch for risky experiments, so any bad change can be thrown away cleanly.

Commit Before You Prompt

Kitty works. You ask a coding agent for one more feature, and it edits seven files. Now nothing loads, and you cannot remember what those files looked like an hour ago. Neither can the assistant. With an assistant that can change many files in seconds, you need an undo button that covers the whole project. Version control is that button.

The rule

Commit a working state before each AI change, so every mistake is undoable.

Git, the most widely used version control system, records commits: snapshots of your project that you can compare with and return to. The everyday rhythm around an assistant is short:

git status                  # anything unsaved? start from a clean state
git add -A                  # stage every change
git commit -m "Record expenses and list them"
# ...now ask the assistant for the next change...
git diff                    # what did it change in tracked files?
git restore .               # throw those changes away, if you need to

A few details matter:

  • git restore . discards unstaged edits to files git already tracks. Brand-new files the assistant created are not touched; git status lists them so you can delete them.
  • For a riskier experiment, use a branch, a separate line of work: git switch -c uneven-splits. If it goes well you merge it into your main branch; if not, you switch back and delete it.
  • Write commit messages for future you: say what changed and why, like "Store amounts in paise to stop rounding errors", not "stuff".

The shortcut

Before every prompt, run green, commit, prompt: the tests pass (green), you commit, and only then do you ask for the change. Never prompt on top of uncommitted work you would hate to lose.

Letting an agent attempt uneven splitsStep 1 of 4
  1. Green

    Kitty's tests all pass, and the app works when you try it by hand.

The trap is the long unsaved stretch: an hour of prompts, some good and some bad, and no commit in between. Then the only choices are keeping everything or losing everything.

Drills

Answer fast — trust the rule.

quick drill

Why commit before asking an assistant for a change?

quick drill

What does git diff, with nothing after it, show after the assistant edits files?

quick drill

The assistant's change tangled five files and you committed just before prompting. What is the best move?

quick drill

Which commit message is the most useful?

quick drill

Where should a risky experiment like uneven splits happen?

Remember

  • Rule: commit a working state before each AI change, so every mistake is undoable.
  • Shortcut: green, commit, prompt. Use a branch for anything risky.
  • Trap: a long stretch of prompts with no commit, leaving you all-or-nothing.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainA safe experiment

Describe, step by step, how you would use commits and a branch to let an assistant attempt uneven splits in Kitty, and what you would do if the attempt went badly.