| name | using-git-worktrees |
| description | Creates isolated Git worktrees for parallel development on different branches. Prevents context-switching overhead and merge conflicts. Activates when starting new development. |
Using Git Worktrees
The using-git-worktrees skill leverages Git worktrees to create isolated working directories for parallel development. This enables working on multiple features or fixes simultaneously without context-switching overhead.
When to Use
Activate using-git-worktrees when:
- Starting new feature development
- Need to work on multiple things simultaneously
- Bug fix is urgent but current work isn't ready
- Want to avoid stashing or committing unfinished work
- Planning to work in parallel with subagents
Why Worktrees Instead of Branches?
Traditional Branch Approach
main ───●─────●───── work on feature A
└──●─────●───── switch back to feature A
Problems:
- Uncommitted work must be stashed or committed
- Switching contexts is disruptive
- Hard to work on multiple features simultaneously
Worktree Approach
main ───●
│
├── feature-A ───●─────●───── isolated worktree
│
└── bug-fix ───●─────●───── different worktree
Benefits:
- Multiple branches visible as separate directories
- No stashing required - worktree has its own working directory
- Switch between tasks by changing directories
- Parallel development without conflicts
The Process
1. Assess Current State
Check current working directory:
git status
git branch
Determine:
- Is there uncommitted work?
- What branch are you on?
- What branch do you need?
2. Create Worktree
Create a new worktree for your task:
git worktree add [path] [branch-name]
Examples:
git worktree add ../feature-notifications feature/notifications
git worktree add ../bugfix-login bugfix/login-broken
git worktree add ../hotfix-urgent hotfix/vip-crash
3. Configure Worktree
In the new worktree:
cd ../feature-notifications
pwd
git status
cargo build
cargo test
4. Work in Isolation
Each worktree operates independently:
- Worktree 1:
~/projects/myapp/feature-auth
- Worktree 2:
~/projects/myapp/feature-notifications
- Main repo:
~/projects/myapp
Switch between worktrees by changing directories:
cd ../feature-auth
cd ../feature-notifications
5. Sync Changes
When ready to merge:
git pull origin main
git checkout main
git merge feature/notifications
git worktree remove ../feature-notifications
git branch -d feature/notifications
Worktree Management
List All Worktrees
git worktree list
Output:
~/projects/myapp 8f12a3c [main]
~/projects/feature-auth 9b8c7d4 [feature/auth]
~/projects/bugfix-login 2d3e4f5 [bugfix/login]
Remove Worktree
git worktree remove ../feature-auth
git worktree remove --force ../feature-auth
Prune Stale Worktrees
git worktree prune
Directory Naming Conventions
Choose clear, consistent names:
../feature-[name] # New features
../bugfix-[issue] # Bug fixes
../hotfix-[severity] # Urgent fixes
../refactor-[module] # Refactoring
../experiment-[name] # Exploratory work
Use Cases
Use Case 1: Urgent Bug Fix
Scenario: Working on feature A, but critical bug is reported.
Without worktree:
- Stash or commit current work
- Checkout/create bugfix branch
- Fix bug
- Merge/release
- Go back to feature A
- Unstash/reapply work
With worktree:
git worktree add ../bugfix-login hotfix/login-crash
- Navigate to bugfix-login
- Fix bug
- Merge/release
- Done - feature-a worktree untouched
Use Case 2: Parallel Features
Scenario: Need to implement two related features.
Approach:
git worktree add ../feature-payments feature/payments
git worktree add ../feature-refunds feature/refunds
- Work on payments in one directory
- Work on refunds in another
- Integrate when both ready
Use Case 3: Subagent Development
Scenario: Dispatching multiple subagents.
Approach:
- Create worktree for each subagent
- Each subagent works in isolation
- Review each worktree's output
- Merge completed worktrees
- Clean up when done
git worktree add ../agent-1-user-module agent/user-module
git worktree add ../agent-2-auth-module agent/auth-module
Anti-Patterns to Avoid
❌ Don't create too many worktrees - Hard to track, uses disk space
❌ Don't modify same files in different worktrees - Conflicts when merging
❌ Don't forget which worktree you're in - Use clear directory names
❌ Don't leave worktrees unmerged - Can become stale and confusing
❌ Don't share worktrees - Each should be used by one person/agent
Integration with Development Flow
Complete Workflow
-
Start new work
git worktree add ../feature-new feature/new
cd ../feature-new
-
Implement feature
-
Sync with main
git fetch origin
git rebase origin/main
-
Run tests
cargo test
-
Merge and cleanup
git checkout main
git merge feature/new
git worktree remove ../feature-new
git branch -d feature/new
Best Practices
- Name clearly - Directory and branch names should match
- Stay organized - Keep worktrees in predictable location
- Clean up - Remove when done to save space
- Track worktrees - Use
git worktree list to see all
- Sync regularly - Rebase on main to avoid big merges
- Test before merge - Run full test suite in worktree
Success Criteria
Using worktrees is successful when:
- ✅ Isolated development environment for each task
- ✅ No uncommitted work lost or stashed
- ✅ Easy switching between contexts
- ✅ Clean merge when done
- ✅ No conflicts from parallel work
- ✅ Team can work in parallel
Troubleshooting
"Worktree already exists"
git worktree list
git worktree remove ../duplicate
"Branch already exists"
git branch -a | grep branch-name
git checkout branch-name
git worktree add ../path new-branch-name --create
"Cannot lock"
git worktree prune
git worktree list