Backup Your Code Before Using AI: Complete Guide
Every method to protect your codebase before letting AI make changes. From quick Git commits to automatic snapshots.
You’re about to ask Cursor to refactor your authentication system. Or let Claude Code reorganize your file structure. Or have Copilot update all your API calls.
Stop. Is your code protected?
If not, you’re one bad AI response away from losing work. Here’s how to set up protection properly so recovery is instant when things go wrong.
Why Backups Matter More With AI
Traditional coding is predictable. You make a change, test it, move on. If something breaks, you usually know what you just changed.
AI coding is different:
- AI can modify dozens of files in one operation
- Changes happen faster than you can review them
- AI might “fix” things you didn’t ask about
- AI confidently makes mistakes
The combination of speed and unpredictability means you need better protection than you did before.
The Best Approach: Automatic Snapshots
The most reliable protection is protection you don’t have to think about.
mrq watches your project and captures every file change automatically:
npm install -g mrq-cli
mrq login
mrq watch
Now every change is captured, whether from AI, manual edits, or anything else.
When AI breaks something:
mrq history # See recent snapshots
mrq restore abc123 # Go back to any point
Why this works best:
- Zero effort after setup, nothing to remember
- Every state is recoverable, not just what you committed
- Works across all AI tools and editors
- No discipline required
Developers who work heavily with AI keep mrq running in the background. They iterate as fast as the AI can generate, knowing recovery is always one command away.
Alternative: Git Commits
If you prefer Git-only, you can protect yourself with disciplined commits:
git add -A
git commit -m "checkpoint before AI refactor"
Now if things break:
git checkout . # Discard all changes
# or
git reset --hard HEAD~1 # Undo the commit entirely
The catch: You have to remember to do it. Every time. Before every risky AI operation.
When you’re in flow, iterating quickly and accepting suggestions, stopping to commit feels like an interruption. So you skip it “just this once.” And that’s usually when AI goes haywire.
Git commits work for intentional milestones, but not so well for continuous protection during rapid iteration.
Other Backup Methods (With Limitations)
Git Stash
For quick experiments:
git stash push -m "before AI experiment"
# Try AI stuff...
git stash pop # Restore if it broke
Limitation: Only saves tracked files. Only one stash at a time without extra commands. Easy to forget what’s stashed.
Git Branches
For larger experiments:
git checkout -b experiment/ai-refactor
# Do AI stuff...
git checkout main # If it didn't work
git branch -D experiment/ai-refactor
Limitation: Overhead for quick iterations. Still requires committing on the branch. Branch switching can be slow in large repos.
VS Code Local History
VS Code automatically saves file versions as you work.
Limitation: File-by-file recovery only. Tedious for many files. Only works for files that were open. Easy to forget it exists until you need it.
Copy-Paste Backup
The low-tech option:
cp -r my-project my-project-backup
Limitation: Manual. Takes disk space. No history, just one backup point. Nobody actually does this consistently.
Comparison
| Method | Effort | Reliability | Best For |
|---|---|---|---|
| mrq (automatic snapshots) | Zero after setup | ✓ Always works | Continuous AI protection |
| Git commit | Manual each time | Works if you remember | Intentional milestones |
| Git stash | Manual | Limited | Quick experiments |
| Git branch | Manual | Works | Major refactors |
| Local History | Automatic | File-by-file only | Single file recovery |
| Copy folder | Manual | One point only | One-time backup |
The Recommended Setup
Here’s what works best for serious AI coding:
1. Automatic Snapshots (Continuous Protection)
Run mrq watch when you start working. Every change is captured without any thought.
2. Git Commits (Meaningful History)
When you hit a milestone worth documenting, commit to Git:
git add -A
git commit -m "User registration complete"
This keeps your Git history clean and meaningful, with actual milestones instead of “checkpoint before AI” noise.
3. Branches (Optional, for Experiments)
For major explorations where you might want to compare approaches, use branches.
The result:
- mrq handles continuous protection (every state recoverable)
- Git handles intentional history (clean, meaningful commits)
- You iterate as fast as the AI allows, without fear
What This Looks Like in Practice
# Start of session
cd my-project
mrq watch # Start automatic snapshots
# Work with AI freely
# Accept suggestions, try things, iterate fast
# Everything captured automatically
# Hit a good milestone
git add -A
git commit -m "Feature complete"
# Want to try something risky
# Just try it, mrq has your back
# If it breaks: mrq restore
# End of day
# Git history is clean
# mrq captured everything in between
What If You Didn’t Set Up Protection?
If AI just broke something and you weren’t prepared:
- Don’t close your editor — files may be in memory
- Try Ctrl+Z in each affected file
- Check AI tool checkpoints — Cursor and Claude have them
- Try Local History — might have recent versions
- Check Git — if you happened to commit
But honestly, these are hit-or-miss. Sometimes they work, sometimes they don’t. Prevention is far more reliable than scrambling to recover.
Summary
Best protection: Automatic snapshots (mrq). Zero effort, every state recoverable.
Alternative: Git commits before every risky AI operation. Works if you’re disciplined.
Reality: The one time you forget to commit is the time AI breaks everything.
Set up protection now, before you need it. Your future self will thank you.
Related Reading
- mrq vs Git for AI Coding - When to use each
- AI Broke My Code: How to Fix It - When things go wrong
- AI Deleted My Files: Recovery Guide - File deletion recovery
- How to Safely Use AI Coding Assistants - Complete safety guide
mrq captures every file change automatically. Set it once, recover instantly when AI breaks things.
Written by mrq team