Transform your development workflow from sequential to parallel. Control multiple development streams like a boss. Perfect for agentic coding where multiple AI assistants work on different features simultaneously.
This is a Git Worktree Template Repository ready for your next project!
-
Clone or fork this repository
git clone <this-repo-url> your-project-name cd your-project-name
-
Start creating your worktrees
./worktree-manager.sh create feature/your-first-feature
-
Open in Cursor/VS Code
cursor myproject.code-workspace # or code myproject.code-workspace -
Start developing!
- Your project files go in the main directory
- Each feature gets its own worktree
- Use the included tools and guides below
Imagine having multiple versions of your codebase open simultaneously, each in its own branch, each with its own terminal, each potentially running a different AI coding assistant. No more context switching. No more stashing changes. No more "let me just quickly fix this bug" interrupting your feature work.
This is Boss Mode for developers.
Feature A → Switch Branch → Stash → Bug Fix → Switch Back → Unstash → Lost Context 😫
Feature A ────────────────→ Complete ✅
Feature B ────────────────→ Complete ✅
Bug Fix ──→ Complete ✅
Review ────→ Complete ✅
All happening in parallel!
Run multiple AI coding assistants (Claude Code, Copilot, etc.) simultaneously:
- Terminal 1: Claude working on authentication
- Terminal 2: Claude implementing data processing
- Terminal 3: Claude fixing bugs
- Terminal 4: You reviewing and coordinating
- Each worktree maintains its own state
- Switch between features instantly
- No stashing, no merge conflicts from switching
- Keep your mental model intact
The Cursor/VS Code workspace shows all branches at once:
📁 🏠 Main Branch
📁 🔐 Feature: Authentication
📁 📊 Feature: Data Processing
📁 🚨 Hotfix Branch
- See all active development streams
- Monitor progress across features
- Coordinate complex releases
- Manage team members' work areas
# Clone this repo
git clone <your-repo-url>
cd test-workspace-worktree
# Make the manager script executable
chmod +x worktree-manager.sh
# Create your first worktree
./worktree-manager.sh create feature/my-awesome-feature# This opens ALL your worktrees in one window
cursor myproject.code-workspace
# or
code myproject.code-workspaceOpen multiple terminals (one per worktree) and start coding:
# Terminal 1 (Authentication worktree)
claude "implement OAuth2 login with Google"
# Terminal 2 (Data worktree)
claude "create data validation pipeline"
# Terminal 3 (Main branch)
claude "update documentation"Scenario: You're building a SaaS app with multiple features in development
# Create worktrees for each feature
./worktree-manager.sh create feature/user-authentication
./worktree-manager.sh create feature/payment-integration
./worktree-manager.sh create feature/email-notifications
./worktree-manager.sh create feature/analytics-dashboard
# Open the workspace
cursor myproject.code-workspace
# Now you have 4 terminals, 4 Claude instances, 4 features progressing in parallel!Boss Move: Start each morning by checking progress across all worktrees:
./worktree-manager.sh statusScenario: Critical bug in production while you're deep in feature work
# Don't panic! Create a hotfix worktree
./worktree-manager.sh create hotfix/critical-payment-bug
# Switch to it instantly
./worktree-manager.sh switch hotfix/critical-payment-bug
# Fix it with Claude
claude "fix the payment processing timeout issue in checkout.py"
# Meanwhile, your feature work remains untouched!Scenario: Review PRs without contaminating your workspace
# Create a review worktree
./worktree-manager.sh create review/pr-456
# In that worktree
git fetch origin pull/456/head:review/pr-456
git checkout review/pr-456
# Test everything in isolation
npm test
claude "analyze this PR for security vulnerabilities"Scenario: Try risky refactoring without fear
# Create experimental worktree
./worktree-manager.sh create experiment/crazy-optimization
# Go wild with Claude
claude "refactor this entire module to use async generators"
# If it works, great! If not, just delete it:
./worktree-manager.sh remove experiment/crazy-optimization| Command | Description | Example |
|---|---|---|
list |
Show all worktrees | ./worktree-manager.sh list |
create |
Create new worktree | ./worktree-manager.sh create feature/new-api |
remove |
Delete a worktree | ./worktree-manager.sh remove feature/old-api |
switch |
Open worktree in Cursor | ./worktree-manager.sh switch feature/new-api |
status |
Show status of all worktrees | ./worktree-manager.sh status |
clean |
Remove all worktrees (except main) | ./worktree-manager.sh clean |
# List all worktrees with details
git worktree list
# Add worktree with new branch
git worktree add worktrees/feature-x -b feature/x
# Add worktree from existing remote branch
git worktree add worktrees/feature-y origin/feature/y
# Remove worktree (clean)
git worktree remove worktrees/feature-x
# Force remove (with uncommitted changes)
git worktree remove --force worktrees/feature-x
# Clean up stale worktree info
git worktree prune# Create a coordination script
cat > coordinate.sh << 'EOF'
#!/bin/bash
echo "🎯 Deploying AI Agents..."
# Agent 1: Frontend
(cd worktrees/feature-frontend && claude "implement responsive dashboard") &
# Agent 2: Backend
(cd worktrees/feature-backend && claude "create REST API endpoints") &
# Agent 3: Database
(cd worktrees/feature-database && claude "optimize query performance") &
wait
echo "✅ All agents completed!"
EOF
chmod +x coordinate.sh
./coordinate.sh# Search across ALL worktrees
grep -r "TODO" worktrees/
# Run tests across all worktrees
for dir in worktrees/*/; do
echo "Testing $dir"
(cd "$dir" && npm test)
done
# Sync all worktrees with main
for dir in worktrees/*/; do
(cd "$dir" && git pull origin main)
doneAdd to your .code-workspace file:
{
"folders": [
{
"name": "🏠 Main Branch",
"path": "."
},
{
"name": "🚀 Feature: ${featureName}",
"path": "worktrees/feature-${featureName}"
}
],
"settings": {
"terminal.integrated.profiles.osx": {
"worktree-main": {
"path": "bash",
"args": ["-c", "cd ${workspaceFolder:🏠 Main Branch} && bash"]
}
}
}
}Create .git/hooks/post-checkout:
#!/bin/bash
echo "📍 Switched to $(git branch --show-current)"
echo "📊 Status: $(git status --porcelain | wc -l) uncommitted changes"You're a CTO with 3 developers and 2 weeks to launch:
# Create worktrees for each developer
./worktree-manager.sh create dev/alice-payment
./worktree-manager.sh create dev/bob-auth
./worktree-manager.sh create dev/charlie-frontend
# Daily standup: Check all progress
./worktree-manager.sh status
# Integrate features
cd worktrees/integration
git merge dev/alice-payment dev/bob-auth dev/charlie-frontend# Organize by client
./worktree-manager.sh create client/acme-corp
./worktree-manager.sh create client/wayne-enterprises
./worktree-manager.sh create client/stark-industries
# Each client gets dedicated AI assistant
# Never mix up client code again!# Handle multiple PRs simultaneously
./worktree-manager.sh create pr/feature-1234
./worktree-manager.sh create pr/bugfix-5678
./worktree-manager.sh create pr/docs-9012
# Test all PRs in parallel
parallel --jobs 3 'cd worktrees/{} && npm test' ::: pr/*feature/payment-integration # Features
bugfix/issue-1234 # Bug fixes
hotfix/critical-security # Emergency fixes
experiment/new-architecture # Experiments
review/pr-5678 # PR reviews
release/v2.0.0 # Release prep
dev/alice-feature # Personal branches# Morning: Check status
./worktree-manager.sh status
# Before creating: Check if exists
git worktree list | grep feature-name
# After merging: Clean up
./worktree-manager.sh remove feature/completed-feature
# Weekly: Prune stale worktrees
git worktree prune- Keep worktrees on the same disk as main repo
- Limit active worktrees to 5-7 for best performance
- Use
git worktree pruneregularly - Consider separate worktrees for large binary files
# Share worktree setup
git add myproject.code-workspace
git commit -m "Add team workspace configuration"
# Document active worktrees
echo "## Active Development" >> WORKTREES.md
git worktree list >> WORKTREES.md# Solution 1: Remove and recreate
git worktree remove worktrees/branch-name
./worktree-manager.sh create branch-name
# Solution 2: Force removal
rm -rf worktrees/branch-name
git worktree prune# Save changes first
cd worktrees/feature-branch
git stash save "WIP: Saving before worktree removal"
# Or force remove
git worktree remove --force worktrees/feature-branchcd worktrees/problem-worktree
git checkout correct-branch
git pull origin correct-branch# Manual cleanup
rm -rf .git/worktrees/broken-worktree
git worktree pruneWith this setup, you can:
- ✅ Run multiple AI coding sessions in parallel
- ✅ Handle emergencies without disrupting feature work
- ✅ Review code without contaminating your workspace
- ✅ Experiment fearlessly with isolated environments
- ✅ Coordinate team development like a pro
- ✅ Ship features faster with parallel development
- Create your first feature worktree
- Open the boss workspace in Cursor/VS Code
- Start your first parallel AI coding session
- Experience the power of true parallel development
Remember: You're not just coding anymore. You're orchestrating a symphony of development streams. You're the boss of your codebase.
Built with ❤️ for developers who refuse to work sequentially
Questions? Check the worktree-guide.md for more details.
Contributing? Create a worktree for your feature and submit a PR!
|
Marcus 💻 📖 🤔 🎨 |
See our Contributors Guide for more information.