AI Coding Tip 001 - Commit Before Prompt

Published: (January 6, 2026 at 06:00 AM EST)
3 min read
Source: Dev.to

Source: Dev.to

Cover image for AI Coding Tip 001 - Commit Before Prompt

A safety‑first workflow for AI‑assisted coding

TL;DR

Commit your code before asking an AI Assistant to change it.

Common Mistake ❌

Developers ask an AI assistant to “refactor this function” or “add error handling” while they have uncommitted changes from their previous work session. When the AI makes its changes, the git diff shows everything mixed together—their manual edits plus the AI’s modifications—making it hard to separate what broke and to revert safely.

Problems Addressed 😔

  • Mixing previous code changes with AI‑generated code.
  • Losing track of what was changed.
  • Struggling to revert broken suggestions.

How to Do It 🛠️

  1. Finish your manual task.
  2. Run your tests to ensure everything passes.
  3. Commit your work with a clear message, e.g. feat: manual implementation of X.
  4. (No need to push the commit.)
  5. Send your prompt to the AI assistant.
  6. Review the changes using your IDE’s diff tool.
  7. Accept or revert: keep the changes if they look good, or run git reset --hard HEAD to instantly revert.
  8. Run the tests again to verify the AI changes didn’t break anything.
  9. Commit AI changes separately, e.g. refactor: AI‑assisted improvement of X.

Benefits 🎯

  • Clear diffing – see the AI’s suggestions in isolation.
  • Easy revert – undo a bad AI hallucination instantly.
  • Context control – ensure the AI works on your latest, stable logic.
  • Tests stay green – you’re not breaking existing functionality.

Context 🧠

When you ask an AI to change your code, it might delete crucial logic or rename variables across several files. Uncommitted changes hide what the AI did versus what you did manually. By committing first you create a safety net; git diff shows exactly what the AI modified, and a single git reset --hard HEAD restores the clean state. Working in very small increments further reduces risk. Some assistants are not good at undoing their changes.

Prompt Reference 📝

git status              # Check for uncommitted changes
git add .               # Stage all changes
git commit -m "msg"     # Commit with message
git diff                # See AI's changes
git reset --hard HEAD   # Revert AI changes
git log --oneline       # View commit history

Considerations ⚠️

Only necessary if you work in write mode and your assistant is allowed to modify the code.

Type 📝

  • Semi‑Automatic – you can enforce rules for the assistant to check repository status before making changes.

Limitations ⚠️

If your code is not under a source‑control system, you’ll need to apply this workflow manually.

Tags 🏷️

  • Complexity

Level 🔋

  • Beginner
  • Use TCR
  • Use Vibe Test Driven Development
  • Break large refactorings into smaller prompts
  • Git Bisect for AI Changes: using git bisect to identify which AI‑assisted commit introduced a defect
  • Reverting Hallucinations

Conclusion 🏁

Treating AI as a pair programmer requires the same safety practices you’d use with a human collaborator: version control, code review, and testing. Committing before prompting creates clear checkpoints that make AI‑assisted development safer and more productive. This simple habit turns AI from a risky black box into a powerful tool you can experiment with confidently, knowing you can always return to a working state. Commit early, commit often, and don’t let AI touch uncommitted code.

More Information ℹ️

TCR

Tools 🧰

GIT is an industry standard, but you can apply this technique to any other version‑control software.

This article is part of the AI Coding Tip series.

Back to Blog

Related posts

Read more »

Rapg: TUI-based Secret Manager

We've all been there. You join a new project, and the first thing you hear is: > 'Check the pinned message in Slack for the .env file.' Or you have several .env...

Technology is an Enabler, not a Saviour

Why clarity of thinking matters more than the tools you use Technology is often treated as a magic switch—flip it on, and everything improves. New software, pl...