Skip to content

Git checkpoint and rollback pattern for vibe coding with AI

pattern

Asking AI to fix its own bugs creates compounding errors; each fix attempt introduces new issues

debugginggitvibe-codingcheckpointsworkflow
22 views

Problem

When an AI coding agent introduces a bug, the natural instinct is to tell it "not working, try again." The agent then applies a fix that introduces a new bug, which you ask it to fix again, creating a cascade of patches on top of patches. After several iterations you end up with bloated, redundant code that is worse than where you started, and the original bug may still not be fixed.

Solution

Step 1: Commit after every working state

# After each successful change, checkpoint immediately
git add -A && git commit -m "working: added user list component"

# Use a consistent prefix so checkpoints are easy to find
git log --oneline | head -5
# a1b2c3d working: added user list component
# d4e5f6g working: connected auth flow
# h7i8j9k working: initial dashboard layout

Step 2: When a bug appears, stop and diagnose

Do not tell the AI to fix it. Instead, ask it to analyze the problem in chat mode without making changes:

# In your AI tool's chat mode (not edit mode):
"The user list is not rendering after the last change.
What is wrong? Analyze the issue but do not make any changes."

Step 3: Roll back to the last good state

# Reset to the last working checkpoint
git reset --hard HEAD~1

# Or reset to a specific checkpoint
git reset --hard a1b2c3d

Step 4: Apply the fix with full context

Paste the diagnosis from step 2 back into the agent with an explicit fix instruction:

"The previous attempt to add filtering broke the user list
because the filter function returned undefined for empty arrays.
Add the filtering feature but ensure the list renders correctly
when the filter result is empty by returning an empty array
instead of undefined."

Step 5: Verify and checkpoint again

# Test the fix, then checkpoint
git add -A && git commit -m "working: added filtering with empty state handling"

The complete loop:

1. Make change -> works? -> git commit (checkpoint)
2. Make change -> broken? -> ask "what's wrong?" in chat
3. git reset --hard to last checkpoint
4. Paste the diagnosis + explicit fix instruction
5. Repeat from step 1

Why It Works

This pattern breaks the destructive cycle of AI-fixing-AI-mistakes. Each rollback returns to known-good code, so fixes are applied cleanly instead of layered on top of previous failed attempts. The diagnosis step captures the AI's understanding of the root cause while the code is still broken, and this understanding is preserved even after the rollback. The agent then applies one clean fix with full context about what went wrong, rather than blindly iterating.

Context

  • This is the single most important workflow improvement for vibe coding according to practitioners
  • Works in any AI tool: Cursor, Claude Code, Cline, Zed Agent, Lovable, or copy-paste workflows
  • Git checkpoints cost nothing and take seconds; commit more often than feels necessary
  • The "ask what's wrong, then rollback and fix" pattern also works across tools: diagnose in one tool, fix in another
  • For larger projects, use git stash or branches instead of reset if you want to preserve the broken state for reference
  • Never let the AI iterate more than twice on the same bug without rolling back
About this share
Contributormblode
Repositorymblode/shares
CreatedFeb 10, 2026
View on GitHub