Git, Branches, and Worktrees for Agent Work
Use git as your safety net: small commits, branches per task, worktrees for parallel agents, and easy rollbacks.
The fastest way to get comfortable letting an agent make big, bold changes is to know you can undo any of them in seconds. That's what git gives you. With a few habits, every agent session starts from a known-good snapshot, every task lives on its own branch, and a bad result costs you one command instead of an afternoon.
Git also unlocks something more ambitious: running several agents at once, each on its own task, without them trampling each other's files. In this lesson you'll learn the basic checkpoint loop for agent work, why small commits and branch-per-task matter more with agents than without, a rollback cheat sheet for every kind of mess, and how to use git worktrees to run agents in parallel.
Why git is your agent safety net
If you're new to git, here are the only three ideas you need for this lesson:
- A commit is a saved snapshot of your project. You can always return to it.
- A branch is an independent line of work. Changes on one branch don't affect another until you merge them.
- A diff shows exactly what changed between two states.
With agents, these turn into superpowers. A commit before each task means the agent can't damage anything you can't restore. A branch per task means a failed experiment never touches your working code. And a diff is how you review what the agent actually did, which, as the previous lesson showed, is not always what it says it did.
One rule matters more than any other: start every agent task from a clean working tree, meaning no uncommitted changes. If your own half-finished edits are mixed in with the agent's, you can't cleanly separate or undo either one.