Lesson 8 / 29

Git as the Safety Net and the Handoff

Use branches, commits and diffs to keep agent work reviewable and reversible.

Every agent change should be easy to see and undo

Version control is the agent's best safety net. Start from a clean working tree and a dedicated branch (never main), so everything the agent does is a visible diff you can discard. Prefer small commits with clear messages, so you can review step by step and git revert or reset one mistake without losing the rest. The agent's final hand-off should be a branch or pull request with a summary of what changed and why, plus the test results, so a human reviews a diff, not a story. Agents should not push to protected branches, rewrite history, or change CI configuration without explicit approval; enforce that with branch protection and required reviews on the server, not just instructions. Because the agent can read your repository history, remember that anything ever committed (including secrets) may be visible to it.

A branch-per-task checklist

Run it before starting an agent on a real task.

[ ] working tree clean (git status shows nothing)
[ ] new branch for this task (e.g. agent/fix-discount), never main
[ ] tests pass on the branch BEFORE the agent starts (so failures are attributable)
[ ] agent commits in small steps; each message says what and why
[ ] final output = branch/PR + summary + test results, not a chat transcript
[ ] server-side: protected main, required review, required CI checks

Review with git diff, not the chat

The diff is the truth about what changed; the agent's description may be incomplete.

Quick check: Why should the agent work on a dedicated branch?

  • Main branches cannot be read
  • Branches make the model smarter
  • Everything it does is a reviewable, discardable diff
  • It avoids needing tests
Answer

Everything it does is a reviewable, discardable diff — A branch isolates the work and makes undoing it trivial.