Loading WURK...
RomanMotion
RomanMotion
Product ad & launch videos · 3D product visuals · app & AI builder. Concept to final cut in days. Open for projects.

Git for vibe coders: one command undoes your AI agent

Commit before every agent run, branch each task, and any bad AI change rolls back with one command instead of a night spent rebuilding what worked.

Published on October 30, 20265 min read

You gave an AI agent a task, walked away, and came back to a repo that barely runs. The version that worked this morning is gone, and rebuilding it from memory eats the rest of your day. Ten minutes of git hygiene makes that night impossible: whatever the agent does, one command puts you back.

Here's the whole system up front. Commit right before every agent task. Give each task its own branch. Read the diff before you accept anything. Know which of the three undo commands fits your situation. Everything below is just how to make those four habits cost thirty seconds each.

Commit before every agent task

An agent edits faster than you review. If the last commit in your history is your own, every agent change sits on top of a known-good point. A clean working tree at handoff means one command undoes the agent entirely. If you committed nothing, its edits mix with yours and no single command ever separates them again.

The habit, before every handoff:

git add -A && git commit -m "checkpoint before agent task"

Ugly message, doesn't matter. The point is a marker you can return to. Even harnesses built for long-running work with their own planning and verification loop, like the Goals feature in ZCode, still write to the same files you do, so the checkpoint is yours to make, not the tool's. If you're picking a harness, you can try the ZCode agent harness free with our invite link.

Give every task its own branch

One branch per agent task, and main stays boring. Start each one with git switch -c agent/task-name.

Branching buys you three things for free. The agent's work lives somewhere disposable: git branch -D agent/task-name erases it whole instead of untangling it file by file. You can compare it against main with one diff before it touches anything shared. And you can accept good work with a plain merge when it checks out. If the agent wanders off task, main never knew it happened.

Read the diff before you accept anything

git diff main shows every change the agent made, side by side with what you had. It is the single highest-value thirty seconds in this whole routine.

Agents write plausible-looking code, and plausible is not the bar. Skim the diff for the three classics: a test file that quietly disappeared, a config value that got "simplified", a hardcoded key or URL that was nowhere in your code before. Reading the diff is also how you learn what the agent actually did versus what you think you asked for. That gap is where most lost work lives.

The three undo commands, one line each

  • git restore throws away uncommitted changes in your working files. Use it when the agent's edits are still sitting there uncommitted (docs).
  • git revert creates a new commit that cancels out an earlier one. Use it when the bad commit is already pushed or shared with anyone (docs).
  • git reset moves your branch pointer back, as if the commits never happened. Use it only on local history that nobody else has (docs).

The decision rule collapses to one question: has it been committed, and has it been shared? Uncommitted, restore is your friend. Committed but only local, reset makes it vanish. Committed and pushed, revert is the honest fix, because it writes the undo into history instead of pretending the mistake never existed. When in doubt between reset and revert, revert: it works in every case and never rewrites anything someone else might have pulled.

Stash for quick experiments, worktrees for parallel agents

git stash shelves your uncommitted work and hands you a clean tree in one command. Handy when an agent needs a clean slate and your half-finished edit is in the way. git stash pop puts it back exactly as it was.

For running two agents at once, git worktree is the command to learn. It checks out a second branch into its own separate folder, inside the same repository, so each worktree has its own checked-out branch and its own files (docs). Two agents can then work side by side without ever touching each other's working directory, and you stop playing musical chairs with git switch every time you move between tasks. It works from one clone; no need to re-clone the repo per agent.

One note on cost: parallel agents mean more agent hours. If you'd rather pay one subscription than watch a per-prompt meter, the GLM Coding Plan covers agent coding tools including ZCode, in Lite, Pro and Max tiers (docs), and you can get a referral discount on GLM coding plans with our referral link.

Let the agent write the commit message, you check it

Agents summarize well, so outsource the typing, not the judgment. After a chunk of work, ask for a one-line message that states what changed and, on the same line, why.

Then read it before you commit. The test: could someone skimming git log in six months tell what happened from the subject line alone? "Update components" fails. "Drop idle polling in waiter screen to cut API load" passes. If the agent's message describes what you asked for instead of what the diff shows, reject it and say why. That one correction trains you to notice the gap too, and the log stays a record of reality rather than intentions.

The routine: before and after every agent task

Screenshot this. It's the whole article in eight steps.

Before every agent task:

  1. git status, and commit or stash anything lying around
  2. git switch -c agent/<task-name>
  3. git add -A && git commit -m "checkpoint"
  4. hand the agent one bounded task, not a vibe

After the agent finishes:

  1. git diff main, and actually read it
  2. run the tests yourself
  3. check the commit message describes what happened
  4. merge the branch, or delete it without guilt

That's the entire practice. It fits on a phone screen, it costs a few minutes a day, and it converts "the agent destroyed my repo" into "the agent's Tuesday work got reverted in ten seconds." More teardowns like this on our blog.

Related reading: Stop eyeballing releases: catch visual bugs with screenshot diffs.

If this saved you an hour, a small tip on this post keeps these guides coming.

Conversation

Join the conversation

Share your thoughts with the author and other readers.

Comments0

Checking your account…

Latest comments

0
No comments yet. Be the first to share your thoughts.