Skip to content

What Git Workflow Should You Use With AI Coding Tools?

Problem

When I started using AI coding tools like Claude Code and Cursor, I made mistakes. I let the AI commit directly to my main branch. I skipped reviewing changes before committing. I trusted the AI too much.

The result? Broken builds, unintended file deletions, and code that looked correct but introduced subtle bugs. I needed a better approach.

The question I had: What Git workflow actually works with AI coding assistants?

After reading community discussions and experimenting with different approaches, I found an answer that works. The key insight: treat AI like an unpredictable but productive pair programmer, and use Git as your safety net.

The Core Workflow: Branch, Review, Commit, Never Auto-Push

The community consensus is clear on the essential practices:

1. Always Use Feature Branches

Never let AI work directly on main or master. Create a dedicated branch for each AI-assisted task:

Create feature branch for AI work
# Before starting any AI session
git checkout main
git pull origin main
git checkout -b ai-feature/task-name-$(date +%Y%m%d)

This isolation means AI mistakes stay contained. If something goes wrong, I can abandon the branch without affecting my main codebase.

2. Review Every Change Before Committing

The most important rule: never let AI commit blindly. I review every diff:

Review changes before committing
# Check what the AI changed
git status
git diff
# Review staged changes too
git diff --cached

One developer shared: “git is your safety net. i review every change it makes before committing. worst case you git reset and lose 10 minutes.”

This mindset shift is crucial. AI generates code faster than I can think, but reviewing takes seconds and prevents hours of debugging.

3. Never Allow AI to Push Directly

Disable any “auto-push” features in your AI tools. Push should always be a manual human action:

Manual push workflow
# Review first
git log -p HEAD~3 # Check recent commits
# Only push when satisfied
git push origin ai-feature/task-name

The reason is simple: once code is pushed to a shared branch, it affects teammates. AI mistakes become team problems.

4. Keep Commits Small and Focused

AI tends to make broad changes across many files. I break these into logical commits:

Split AI changes into focused commits
# Add files selectively, not all at once
git add src/components/Button.tsx
git commit -m "fix: Button component prop handling"
git add src/utils/validation.ts
git commit -m "add: input validation helpers"
# Avoid: git add . && git commit -m "AI changes"

Small commits make rollbacks easier and code reviews meaningful.

The Safety Net: Git Reset and Recovery

When AI makes unwanted changes, Git reset is your recovery tool.

Soft Reset: Keep Changes, Undo Commit

When the AI committed something but I want to review more:

Soft reset preserves changes
# Undo last commit, keep changes in staging
git reset --soft HEAD~1
# Now review the staged changes
git diff --cached

Hard Reset: Discard All Changes

When the AI completely messed up and I want to start fresh:

Hard reset discards everything
# WARNING: This deletes uncommitted changes
git reset --hard HEAD
# Or reset to a specific earlier commit
git reset --hard abc1234

The “Worst Case” Mindset

Another developer put it well: “worst case you git reset and lose 10 minutes.”

This is the key perspective. AI can generate code quickly, so losing 10 minutes of work isn’t catastrophic. What would be catastrophic is losing hours or days because AI pushed broken code to production.

Branching Strategy for AI Work

I use a specific branching pattern for AI-assisted development.

The AI Feature Branch Pattern

Branch naming convention
ai-feature/<description>-<date>
Examples:
ai-feature/add-auth-20260325
ai-feature/refactor-api-20260325
ai-feature/fix-login-bug-20260325

This naming convention helps me:

  • Identify which branches have AI-generated code
  • Know when the branch was created
  • Find branches for cleanup later

The Review Branch Workflow

For larger AI tasks, I add a review step:

Workflow diagram
main --> ai-feature/task --> review/fixes --> main
1. Create AI feature branch from main
2. Let AI generate code
3. Review all changes
4. Create fixes if needed
5. Merge back to main after testing

Daily Workflow Example

Here’s my typical session with Claude Code:

Complete AI coding session workflow
# 1. Start from clean state
git checkout main
git pull origin main
git status # Confirm clean
# 2. Create AI branch
git checkout -b ai-feature/add-user-validation-20260325
# 3. Work with AI (Claude Code session)
# ... AI makes changes ...
# 4. Review everything
git status
git diff
# 5. Commit selectively
git add src/validators/user.ts
git commit -m "add: user input validation"
git add src/tests/user.test.ts
git commit -m "test: add validation tests"
# 6. Run tests
npm test
# 7. If tests pass, push for review
git push origin ai-feature/add-user-validation-20260325
# 8. Create PR or merge after review
gh pr create --title "Add user validation" --body "AI-assisted implementation"

Common Pitfalls and How to Avoid Them

Pitfall 1: Trusting AI to Delete Files

AI sometimes suggests deleting “unused” files that are actually needed.

Solution: Never let AI delete files without explicit review:

Check deletions carefully
# See what files were deleted
git diff --name-status | grep "^D"
# Restore accidentally deleted files
git checkout HEAD -- path/to/important-file.ts

Pitfall 2: AI Rewriting Existing Code Without Asking

AI may “optimize” code that was intentionally written a certain way.

Solution: Use git diff to catch unexpected rewrites:

Catch unexpected rewrites
# Check for unexpected changes in existing files
git diff --stat
# If too much changed, ask AI to explain
# Or reset and try again with more specific instructions

Pitfall 3: Multiple AI Sessions on Same Branch

Mixing AI-generated code from different sessions creates merge conflicts and unclear history.

Solution: One task per branch. Create fresh branches for new AI tasks:

Clean branch per task
# Don't continue on old AI branch
git checkout main
git checkout -b ai-feature/new-task-20260325

Team Considerations

When working on a team with AI coding tools:

Communication

Label AI-assisted PRs clearly:

PR description template
## AI Assistance Notice
This PR was created with AI coding assistance.
- Tool: Claude Code / Cursor
- Areas affected: [list files/modules]
- Human review: [what was manually verified]

Code Review Standards

Don’t lower review standards for AI code. In fact, review AI code more carefully:

  • AI can introduce subtle bugs that look correct
  • AI may not follow team conventions consistently
  • AI might miss edge cases that humans would catch

Branch Protection

Enable branch protection rules:

Branch protection settings
main:
- Require pull request reviews
- Require status checks (CI/tests)
- Do not allow direct pushes
- Require linear history

This prevents AI (or humans) from pushing directly to protected branches.

Comparison: AI Workflow vs Traditional Workflow

Workflow comparison
Traditional:
Code -> Review -> Commit -> Push -> Deploy
AI-Assisted:
Code(AI) -> Review(Human) -> Commit(Human) -> Push(Human) -> Deploy
Key difference: Human is always in the loop for decisions

The human stays in control at decision points. AI generates options, humans make final calls.

Summary

In this post, I showed a Git workflow that works safely with AI coding tools. The key practices are:

  1. Branch-based work: Always create feature branches for AI tasks
  2. Human commits: Review every change before committing, never let AI commit blindly
  3. Manual push: Never allow auto-push, always verify before pushing
  4. Git as safety net: Use reset and recovery when AI makes mistakes
  5. Small commits: Break AI changes into focused, reviewable commits

The core principle: AI writes code, but humans control what gets committed and pushed. Git is your recovery mechanism when things go wrong.

When I follow this workflow, I get the productivity benefits of AI coding while maintaining code quality and safety. The worst case is losing 10 minutes to a git reset --hard, not losing hours to broken production code.

Final Words + More Resources

My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments