A safety-first workflow for AI-assisted coding
TL;DR: Commit your code before asking an AI Assistant to change it.
Developers ask AI assistants 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.
If something breaks, they can't easily separate what they did from what the AI did and make a safe revert.
-
You mix your previous code changes with AI-generated code.
-
You lose track of what you changed.
-
You struggle to revert broken suggestions.
-
Finish your manual task.
-
Run your tests to ensure everything passes.
-
Commit your work with a clear message like feat: manual implementation of X.
-
You don't need to push your changes.
-
Send your prompt to the AI assistant.
-
Review the changes using your IDE's diff tool.
-
Accept or revert: Keep the changes if they look good, or run
git reset --hard HEADto instantly revert -
Run the tests again to verify AI changes didn't break anything.
-
Commit AI changes separately with a message like refactor: AI-assisted improvement of X.
Clear Diffing: You see the AI's "suggestions" in isolation.
Easy Revert: You can undo a bad AI hallucination instantly.
Context Control: You ensure the AI is working on your latest, stable logic.
Tests are always green: You are not breaking existing functionality.
When you ask an AI to change your code, it might produce unexpected results.
It might delete a crucial logic gate or change a variable name across several files.
If you have uncommitted changes, you can't easily see what the AI did versus what you did manually.
When you commit first, you create a safety net.
You can use git diff to see exactly what the AI modified.
If the AI breaks your logic, you can revert to your clean state with one command.
You work in very small increments.
Some assistants are not very good at undoing their changes.
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 historyThis is only necessary if you work in write mode and your assistant is allowed to change the code.
[X] Semi-Automatic
You can enforce the rules of your assistant to check the repository status before making changes.
If your code is not under a source control system, you need to make this manually.
- Complexity
[X] Beginner
-
Use TCR
-
Practice Vibe Test Driven Development
-
Break Large Refactorings into smaller prompts
-
Use Git Bisect for AI Changes: Using
git bisectto identify which AI-assisted commit introduced a defect -
Reverting Hallucinations
Treating AI as a pair programmer requires the same safety practices you'd use with a human collaborator: version control, code review, and testing.
When you commit before making a prompt, you create clear checkpoints that make AI-assisted development safer and more productive.
This simple habit transforms 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.
Explain in 5 Levels of Difficulty: GIT
- Commit Before Prompt
GIT is an industry standard, but you can apply this technique to any other version control software.
The views expressed here are my own.
I am a human who writes as best as possible for other humans.
I use AI proofreading tools to improve some texts.
I welcome constructive criticism and dialogue.
I shape these insights through 30 years in the software industry, 25 years of teaching, and writing over 500 articles and a book.
This article is part of the AI Coding Tip series.
