| English | 中文 |
AI makes writing code cheaper. It makes verifying code more expensive.
Git’s new role in the AI era is slicing large AI-generated changes back into engineering units that humans can understand, review, and roll back.
AI-generated code tends to share a few characteristics:
The goal of a Git workflow in the AI era is to make changes small, clear, and verifiable again — not just fast to commit.
Different AI tools integrate with Git differently, but the objective is the same: keep AI modifications inside reviewable, rollback-ready engineering units. Codex emphasizes remote environments and sandboxes; Claude Code emphasizes worktree isolation; Copilot Cloud Agent follows an Issue-to-PR model; Aider treats local Git commits and reverts as a first-class experience. See Git Integration Practices for AI Coding Tools for a detailed comparison.
Each commit expresses one complete intent.
If an AI touches 20 files at once, review the diff first, then split it into multiple commits.
One branch per task.
AI exploratory changes should never land directly on main, master, develop, or any long-lived maintenance branch.
Before committing, inspect:
git status
git diff
git diff --stat
If you can’t explain in a few minutes why this diff exists, don’t commit it yet.
Every AI change must leave behind a way to verify it:
AI can generate code, explain diffs, and run an initial review pass — but the final merge decision belongs to a human.
Every PR must answer:
git revert enough?git switch main
git pull --rebase
git switch -c feat/ai-assisted-short-task
Use worktrees when running multiple AI tools on different tasks in parallel:
git worktree add ../my-project-task-a -b feat/task-a
git worktree add ../my-project-task-b -b feat/task-b
See official documentation: git worktree.
Keep prompts specific and bounded:
Modify only the order validation logic, do not adjust interface signatures, and do not change irrelevant formatting.
Upon completion, list changed files, behavioral changes, validation methods, and potential risks.
git status
git diff --stat
git diff
Look for:
Use interactive staging to carve up changes:
git add -p
git commit -m "fix(auth): handle expired token"
If the AI already landed everything in one large commit:
git reset --soft HEAD~1
git add -p
Only do this on local commits that haven’t been pushed.
When AI generates a large cross-layer feature, consider breaking it into a stack of smaller dependent PRs so that tests, implementation, cleanup, and docs each go through review separately. See Stacked PR for AI-Generated Changes for details.
Run the minimum necessary tests for your project type:
npm test
mvn test
go test ./...
pytest
If there are no tests, document the local verification steps explicitly.
Ask AI to check against a fixed list:
Please perform a Review based on the current git diff.
Focus checks on: behavioral boundaries, error handling, compatibility, test validity, security risks, and irrelevant changes.
Do not provide vague summaries; list only specific risks and file locations.
The PR description must include at least:
You can directly use the PR Template.
CI is the minimum quality bar for AI-generated code — treat it as non-negotiable.
If your team uses GitHub, enforce this with branch protection rules, required status checks, and review requirements. See GitHub branch protection docs.
docs: explain the behavior
test: cover the failing case
fix: change the implementation
refactor: simplify local helper
fix all ai changes
update files
misc
wip
A commit should independently answer:
feat/short-description
fix/bug-description
docs/topic-name
ai/experiment-short-description
ai/task-a
ai/task-b
ai/review-task-a
Pair multi-agent work with git worktree to prevent multiple tools from competing over the same files.
See AI Code Review Checklist for the full template.
For large changes that cross layers or ownership boundaries, split into stacked PRs. A single PR shouldn’t simultaneously carry requirement explanation, code understanding, test verification, and risk assessment.
Risk: The diff is too large to review effectively.
Fix: Ask AI to output a plan first, then execute incrementally in small, scoped tasks.
Risk: Unrelated files, debug code, and config changes get bundled in.
Fix: Always run git diff before staging anything.
Risk: Behavioral changes and structural changes are tangled together.
Fix: Split into multiple commits or separate PRs.
Risk: Work that others built on top of old commits is lost.
Fix: On public branches, prefer new commits for corrections. If history rewriting is truly necessary, confirm with collaborators first.
git switch main
git pull --rebase
git switch -c fix/order-timeout-validation
# AI modifies files
git status
git diff --stat
git diff
git add -p
git commit -m "test(order): cover timeout validation"
git add -p
git commit -m "fix(order): reject expired timeout config"
mvn test -pl order-service -Dtest=OrderTimeoutValidatorTest
git push -u origin fix/order-timeout-validation
In the PR description:
What changed:
Add validation for expired timeout config.
How tested:
mvn test -pl order-service -Dtest=OrderTimeoutValidatorTest
Risk:
Low. Only affects invalid timeout config path.
Rollback:
Revert this PR.