Technical
Git for the AI Era: What Changes When Agents Write Code
When an AI agent generates 500 lines of code in 30 seconds, your git workflow needs to adapt. The old approach of committing when it feels right does not work when commits could contain code you have not fully reviewed. Here is how I adapted my git practices.
The Problem
Traditional git workflow: write code for an hour, git add ., git commit -m 'stuff', repeat. This was fine when every line was written by hand and reviewed as you typed it.
AI-assisted workflow needs a different approach because the agent generates large amounts of code quickly. You need to review before staging, commit atomically, and track what was generated versus what was manually written.
Atomic Commits
The most important change: make every commit atomic. One logical change per commit.
# Bad: one big commit with everything mixed together
git commit -m 'built the whole feature'
# Good: atomic commits that each do one thing
git commit -m 'feat: add subscriber model and validation'
git commit -m 'feat: add subscriber creation endpoint'
git commit -m 'test: add subscriber endpoint tests'Why this matters with AI: if an agent-generated commit introduces a bug, you can git revert just that one commit without losing your manual work or other agent-generated code that was correct.
The Review-Before-Staging Pattern
Never use git add . when working with AI agents. Instead, review changes first:
# See what changed across all files
git diff
# Stage only the files you have reviewed and approved
git add src/models/subscriber.py
git add src/routers/subscribers.py
# Leave unreviewed files unstaged for later
git statusThis gives you a review checkpoint between generation and commitment. You control exactly what enters your git history.
Commit Messages That Track Provenance
I include context about how code was generated in commit messages:
git commit -m 'feat(00.4-02): add subscriber validation
- Pydantic EmailStr for email format validation
- Status enum for subscription lifecycle state
- AI-generated scaffold, manually reviewed and adjusted
'This creates an audit trail. Six months from now, you can look at the git log and understand not just what changed but how it was produced.
Branch Strategy for AI Sessions
For AI-heavy work sessions, I use feature branches:
git checkout -b feature/subscriber-endpoints
# ... AI generates code, I review and commit ...
git checkout main
git merge feature/subscriber-endpointsIf the agent goes completely off track, I can discard the entire branch without affecting main. This safety net makes it comfortable to let agents try ambitious changes.
The Minimum Git Commands You Need
You need to know these commands well when working with AI agents:
git diff: See exactly what changed before staging anythinggit add <file>: Stage specific files, nevergit add .git reset HEAD <file>: Unstage a file you added by mistakegit stash: Set aside unfinished work temporarilygit log --oneline: Quick history check to understand recent changes
Everything else, including complex rebases and cherry-picks, let the AI agent handle. Claude Code is excellent at git operations.
See the Pro Git book for the complete reference.
RELATED READING
The Consulting Shift I Am Making In Year Two
After a year of writing and building, my consulting practice is changing shape. Shorter engagements. Sharper outcomes.
ReadThe Frontend Shift: Shipping Less JavaScript In Year Two
A year ago I reached for Next.js for everything. This year I often reach for nothing.
ReadThe Serverless Lesson I Would Write On A Sticky Note
After a year of shipping serverless projects, one rule explains most of the wins and all of the losses.
Read