The Git Workflow
Use Claude Code with branches and commits so every change is reviewable and reversible.
Because Claude Code edits real files, you want the same safety net you use with any teammate: version control.
A safe pattern
- Start from a clean working tree (
git statusshows nothing to commit). - Create a branch for the task.
- Let Claude Code make its edits.
- Review the diff, then commit — Claude Code can write the commit message too.
Why branches matter
Working on a branch means you can experiment freely. If you do not like the result, you switch back to your main branch and the change is gone. If you do, you merge it.
Example
# Prepare a clean, isolated space for the change
git status # make sure the tree is clean
git checkout -b add-dark-mode
# ...let Claude Code make its edits...
# Review, then commit
git diff # read exactly what changed
git add -A
git commit -m "Add dark mode toggle with localStorage persistence"
# Don't like it? Throw it away and go back:
# git checkout main && git branch -D add-dark-modeWhen to use it
- Have Claude Code work on a dedicated feature branch so its changes can be reviewed as a normal pull request.
- Ask Claude Code to commit after each logical step so you can git bisect if something breaks.
- Use git diff to review every file Claude Code changed before merging to main.
More examples
Start from a clean feature branch
Creating a branch first means all of Claude Code's edits are isolated and reviewable via a pull request.
git checkout -b feature/ai-search
claude "Add a semantic search endpoint at /api/search using the existing OpenSearch client"Review Claude Code's changes with diff
Running a diff before committing lets you catch unwanted changes before they enter version history.
# After Claude Code finishes its task:
git diff --stat # see which files changed
git diff src/ # review the actual diffs
git add -p # stage selectively if neededAsk Claude Code to commit each step
Small atomic commits from Claude Code make it easy to revert a specific step without losing all the work.
claude "Add dark-mode support. After each logical step (context, toggle, styles) commit with a descriptive message so I can review the history."
Discussion