Using Git Worktrees
Overview
Git worktrees create isolated workspaces sharing the same repository, allowing work on multiple branches simultaneously without switching.
Core principle: Systematic directory selection + safety verification = reliable isolation.
Directory Selection
Follow this priority order:
1. Check Existing Directories
ls -d .worktrees 2>/dev/null # Preferred (hidden)
ls -d worktrees 2>/dev/null # Alternative
If found, use that directory. If both exist, .worktrees wins.
2. Check CLAUDE.md / Project Config
Look for worktree directory preferences in project configuration.
3. Create Default
mkdir -p .worktrees
Creating a Worktree
# Create branch and worktree
git worktree add .worktrees/<feature-name> -b <feature-branch>
# Verify
cd .worktrees/<feature-name>
git branch # Should show feature branch
pwd # Should be in worktree
Safety Verification
After creating, verify:
- ✅ Correct branch checked out
- ✅ Clean working directory
- ✅ Can run tests independently
- ✅ Not on main/master branch
Cleanup
After merging:
git worktree remove .worktrees/<feature-name>
git branch -d <feature-branch>
Integration
- magic-powers:brainstorming — creates worktree for implementation
- magic-powers:executing-plans — requires worktree before starting
- magic-powers:finishing-a-development-branch — cleanup after merge