All courses

Commit before every task: checkpoints

Make a commit (or use the tool's snapshot feature) before each task and after each accepted step. Then every attempt starts from a known-good state and costs nothing to throw away.

Builds on: Your first small task, end to end

Read it card by card Start the whole course

Your next task breaks: now what?

Your first small task is done and committed. Next you ask: 'also add CSV output'. The agent edits three files and creates a new one. The result is broken. Earlier you had also tweaked `report.py` by hand and never committed it. Which changes are yours and which are the agent's? And how do you get back to the version that worked?

A save point turns attempts into free tries

The agent edits whatever is in your folder right now. Git sees two things: the last commit, and everything changed since then. Commit right before a task, and 'everything changed since' is exactly the agent's attempt. `git status` and `git diff` show only that attempt, and going back to the commit removes only that attempt. A bad try then costs nothing. You can let the agent try, look at the result, and throw it away.

The checkpoint rhythm

1. **Before:** run `git status`. You want `nothing to commit, working tree clean`. If it isn't clean, review what's there and commit it first. 2. **Task:** give the agent one step. 3. **Accept:** you ran the result and read the diff? Commit, with a message saying what changed. 4. **Reject:** return to the last checkpoint and retry. Exact undo commands come in a later lesson. A tool's own snapshot or rewind helps, but it may miss changes made by commands the agent ran. A git commit records the files you add to it, no matter whether the agent, its commands or you changed them.

Same mess, with and without a checkpoint

**Without:** your hand tweak and the agent's edits sit in one diff. To undo the agent, you pick lines apart by hand and may delete your own work. **With:** you commit your tweak first (`Tweak header text`), then ask for CSV output. It breaks. You return to that commit. Your tweak survives, the broken attempt is gone, and you retry with a clearer request.

One task, wrapped in checkpoints

Clean start, one step, run it, read the diff, commit. The agent edited `report.py` and created a new file, `csv_out.py`. The added lines check whether `--csv` was typed after the script name. If it was, they write CSV instead of the table. `git diff` shows only that edit: files git has never saved don't appear in it. `git status` lists both files, so check it and add the new file to the commit too.
$ git status
nothing to commit, working tree clean
▸ You: add a --csv option to report.py
⚙ Edit: report.py
⚙ Create: csv_out.py
$ python report.py --csv
name,total
alice,42
$ git diff
--- a/report.py
+++ b/report.py
@@ -12,2 +12,6 @@ def main():
     rows = load_rows()
+    if "--csv" in sys.argv:
+        from csv_out import write_csv
+        write_csv(rows)
+        return
     print_table(rows)
$ git status
Changes not staged for commit:
  modified:   report.py
Untracked files:
  csv_out.py
$ git add report.py csv_out.py
$ git commit -m "Add --csv option"

Clean before, commit after

Check for a clean `git status` before every task, and commit after every step you accept. Then each attempt starts from a known-good state, `git status` and `git diff` show only that attempt, and throwing it away costs nothing.

On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.