As software architects and developers at vensas, we frequently face the challenge of working on multiple features, bug fixes, or ideas simultaneously. The traditional approach with git checkout means constantly switching between branches, stashing changes, or creating "work-in-progress" commits - all time-wasters that break the flow.
In this post, we'll show how Git Worktrees combined with AI coding agents (such as GitHub Copilot, Claude Code, or Cursor) can elevate development to an entirely new level.
What are Git Worktrees?
Git Worktrees allow the creation of multiple working directories from a single repository, with each directory checked out to a different branch. Unlike git checkout, there's no limitation to one active branch per working directory - multiple features, bug fixes, or experiments can be worked on simultaneously, each isolated in its own folder, but all sharing the same repository history and .git data.
Benefits at a Glance
- True Parallelism: No context switching, stashing, or accidental overwrites
- Low Storage Footprint: All worktrees share the same
.githistory (unlike multiple clones) - Seamless Git Integration: All branches and history remain consistent
- Perfect for Experimentation: Try different approaches in parallel without affecting the main branch
Basic Commands
# Create a new worktree
git worktree add ../feature-x-worktree feature-x
# List all worktrees
git worktree list
# Remove a worktree
git worktree remove ../feature-x-worktree
# Cleanup (removes references to deleted worktrees)
git worktree prune
AI Agents and Parallel Workflows
This is where it gets really interesting: AI coding agents like GitHub Copilot, Claude Code, Cursor, or Aider can be run in parallel in separate worktrees. Each agent gets its own branch and folder, safely isolated from the others.
Practical Scenario
A typical example: A new feature needs to be implemented, but the best approach is still unclear:
1. Create multiple worktrees:
git worktree add ../feature-auth-v1 -b feature-auth-v1
git worktree add ../feature-auth-v2 -b feature-auth-v2
git worktree add ../feature-auth-v3 -b feature-auth-v3
2. Open each worktree in a separate VS Code window
3. Assign an AI agent to each window:
- Window 1: GitHub Copilot implements with OAuth2
- Window 2: Claude Code tries a JWT approach
- Window 3: Cursor experiments with Magic Links
4. Observe, compare, and select:
- All three agents work in parallel
- Implementations can be compared in real-time
- The best solution can be chosen or aspects from multiple approaches combined
- All branches can be merged or the best commits cherry-picked
Branch-per-Agent Pattern
A proven pattern for using AI agents with worktrees:
main/
├── feature-x-agent1/ (GitHub Copilot)
├── feature-x-agent2/ (Claude Code)
└── feature-x-agent3/ (Cursor)
Each agent receives:
- Its own worktree/branch
- Isolated working environment
- No conflicts with other agents
- Complete Git history
Concurrent Testing with Different Configurations
Worktrees also excel at testing:
# Worktree for feature development
git worktree add ../feature-dev feature-branch
# Worktree for tests with mock data
git worktree add ../feature-test feature-branch
# Worktree for integration tests
git worktree add ../feature-integration feature-branch
In each worktree, it's possible to:
- Set different environment variables
- Use different test configurations
- Test mocked vs. real services
- Use different database setups
Scaling for Teams (Real or Virtual)
Worktrees aren't just for solo developers. Teams can use them:
- Multiple Developers: Each works in their own worktree
- Code Reviews: Reviewers can check PRs in separate worktrees without interrupting their current work
- Hotfixes: Quickly create a hotfix in a separate worktree while feature development continues
- Experimentation: Try new approaches without affecting the main branch
Tooling and Automation
Git worktree commands can be somewhat verbose. Here are some tools that help:
Worktrunk CLI
Worktrunk is a CLI specifically designed for large AI agent workflows:
# Installation
cargo install worktrunk
# Create and switch to worktree
trunk new feature-x
# Switch between worktrees
trunk switch feature-x
# Cleanup
trunk clean
Custom Alias Commands
Add these to the .gitconfig:
[alias]
wt = worktree
wta = worktree add
wtl = worktree list
wtr = worktree remove
wtp = worktree prune
Best Practices
Dos
✅ Use worktrees for parallel work: Features, bug fixes, experiments
✅ Combine with AI agents: Let multiple approaches develop in parallel
✅ Use for code reviews: Quick context switching without stashing
✅ Automate with scripts: Create wrapper scripts for common workflows
✅ Isolate test environments: Different configs in different worktrees
Don'ts
❌ Don't use the same branch in multiple worktrees (Git prevents this)
❌ Don't forget to cleanup: Remove worktrees that are no longer needed
❌ Don't ignore .env and configs: These are not automatically synchronized
❌ Don't overdo it: Too many worktrees become hard to manage
Practical Example: Developing a Feature with Three AI Agents
Let us show a concrete example:
# 1. Prepare main repository
cd ~/projects/my-app
git checkout main
git pull
# 2. Create three worktrees for three agents
git worktree add ../my-app-copilot -b feature/user-auth-copilot
git worktree add ../my-app-claude -b feature/user-auth-claude
git worktree add ../my-app-cursor -b feature/user-auth-cursor
# 3. Open VS Code windows
code ../my-app-copilot
code ../my-app-claude
code ../my-app-cursor
# 4. In each window, activate the respective AI agent
# and begin implementation
# 5. Compare after development
cd ~/projects/my-app
git diff feature/user-auth-copilot feature/user-auth-claude
git diff feature/user-auth-claude feature/user-auth-cursor
# 6. Merge best approach or cherry-pick commits
git checkout main
git merge feature/user-auth-copilot # or the best one
# 7. Cleanup
git worktree remove ../my-app-copilot
git worktree remove ../my-app-claude
git worktree remove ../my-app-cursor
git branch -d feature/user-auth-copilot feature/user-auth-claude feature/user-auth-cursor
Turning LLM Non-Determinism into an Advantage
An interesting aspect: AI agents are non-deterministic - the same prompt can produce different solutions. With worktrees, this becomes an advantage:
- Create N worktrees for the same feature
- Have N AI agents work in parallel
- Compare all implementations
- Select the best or combine strengths
This is like a code review with multiple developers, but in a fraction of the time!
Performance and Storage
A common misconception: "Multiple worktrees = multiple storage consumption"
Wrong! Worktrees share the .git history:
# One clone
du -sh my-app/.git # 150 MB
# Three worktrees
du -sh my-app/.git # 150 MB (same!)
du -sh my-app-wt1 # 50 MB (working copy only)
du -sh my-app-wt2 # 50 MB (working copy only)
du -sh my-app-wt3 # 50 MB (working copy only)
# Total: 300 MB
# Three clones would require 450 MB (3 × 150 MB)
Conclusion
Git Worktrees are a game changer for modern development, especially when combined with AI coding agents. They enable:
- True parallelism without overhead
- Efficient use of AI agents for faster development
- Risk-free experimentation with different approaches
- Improved productivity through less context switching
In a world where AI agents are becoming increasingly autonomous and taking on larger projects, mastering worktrees becomes a valuable skill. At vensas, we regularly use this technique to transform our development machines into virtual teams, where we can pursue multiple approaches in parallel, compare them, and select the best solutions.
Further Resources
- Git Worktree Documentation
- Worktrunk CLI
- VS Code Multi-root Workspaces
- Testcontainers for Isolated Test Environments
Need Support?
Want to introduce Git Worktrees and AI agents in your development team, but unsure how to optimize your workflows? We're happy to help! Just contact us via our contact page and we'll work together to make your team ready for modern development practices.
Have you already had experiences with Git Worktrees? Or do you use other strategies for parallel development? We at vensas look forward to your feedback and are happy to exchange best practices!
