Use Git Worktree for AI Assistant Coding
Hauke Jung··4 min readOn this page (6 sections)
If you’re using AI coding assistants like Claude Code, GitHub Copilot, or Cursor, there’s a powerful git feature you’re probably overlooking: git worktree.
The Problem with AI-Assisted Development
When working with AI assistants, you often find yourself in these situations:
- The AI is making changes to your codebase while you want to continue working
- You need to test AI-generated code without risking your current work
- Multiple AI sessions are working on different features simultaneously
- You want to compare AI implementations against your own
Traditionally, you’d either wait, stash your changes, or juggle multiple clones of your repository. All of these options are painful.
Enter Git Worktree
Git worktree lets you check out multiple branches of the same repository into different directories simultaneously. Each worktree shares the same .git directory, so they’re all connected.
# Create a new worktree for AI work
# Now you have:
# /my-project <- your main working directory
# /my-project-ai-feature <- AI assistant's playground
Why This Is Perfect for AI Coding
1. Parallel Workflows
Point your AI assistant at the worktree directory while you continue working in the main directory. No more waiting. No conflicts.
# Terminal 1: You working in main
# Terminal 2: AI assistant working in worktree
2. Safe Experimentation
AI assistants can make sweeping changes. With worktrees, those changes are isolated. If the AI creates a mess, you simply:
Your main directory remains untouched.
3. Easy Comparison
Want to see what the AI did vs. your approach? Both directories exist simultaneously:
Or open both in your IDE side-by-side.
4. Multiple AI Agents
Running multiple AI sessions on different tasks? Create multiple worktrees:
Each AI agent works independently without stepping on each other.
5. Shared Git History
Unlike separate clones, worktrees share the git database. Commits made in any worktree are immediately visible to all others. Merging AI work back into main is seamless.
Practical Workflow
Here’s a typical workflow I use:
# 1. Create a feature branch and worktree for AI
# 2. Point AI assistant at the worktree
# Start AI coding session here
# 3. Continue your own work in main
# Work normally
# 4. Review AI changes
# Run tests, review code
# 5. Merge when satisfied
# 6. Clean up
Tips and Tricks
List all worktrees:
Prune stale worktrees:
Lock a worktree to prevent accidental deletion:
The Bottom Line
Git worktree transforms how you can work with AI coding assistants. Instead of a sequential, blocking workflow, you get parallel, isolated development environments that share the same repository.
The AI can experiment freely. You can work uninterrupted. And when it’s time to integrate, everything is already in the same git repo.
If you’re serious about AI-assisted development, git worktree isn’t just nice to have—it’s essential.
Start small: next time you’re about to let an AI assistant make changes, create a worktree first. You’ll wonder how you ever worked without it.
