| name | worktree |
| description | Manage git worktrees for parallel development. Use to work on multiple branches simultaneously without stashing or switching contexts. |
Git Worktree Manager
Work on multiple branches simultaneously using git worktrees.
Prerequisites
git --version
CLI Reference
List Worktrees
git worktree list
git worktree list --porcelain
Create Worktree
git worktree add ../feature-branch feature-branch
git worktree add -b new-feature ../new-feature main
git worktree add /path/to/worktree branch-name
git worktree add --detach ../temp abc123
Remove Worktree
git worktree remove ../feature-branch
git worktree remove --force ../feature-branch
git worktree prune
Worktree Operations
git worktree move ../old-path ../new-path
git worktree lock ../feature-branch
git worktree lock --reason "long-running task" ../feature-branch
git worktree unlock ../feature-branch
Workflow Patterns
Parallel Feature Development
cd ~/repos/myproject
git checkout feature-a
git worktree add ../myproject-feature-b feature-b
Quick Bug Fix
cd ~/repos/myproject
git worktree add ../myproject-hotfix -b hotfix/urgent main
cd ../myproject-hotfix
git commit -am "fix: urgent bug"
git push origin hotfix/urgent
gh pr create --base main --title "Hotfix: urgent bug"
cd ../myproject
git worktree remove ../myproject-hotfix
Review PR
git fetch origin pull/123/head:pr-123
git worktree add ../myproject-pr-123 pr-123
cd ../myproject-pr-123
npm install
npm test
cd ../myproject
git worktree remove ../myproject-pr-123
git branch -D pr-123
Long-Running Comparison
git worktree add ../myproject-baseline main
cd ~/repos/myproject
npm test > /tmp/feature-tests.log
cd ../myproject-baseline
npm test > /tmp/baseline-tests.log
diff /tmp/baseline-tests.log /tmp/feature-tests.log
Directory Structure
Recommended layout:
~/repos/
├── myproject/ # Main worktree (main branch)
├── myproject-feature-a/ # Feature worktree
├── myproject-feature-b/ # Another feature
└── myproject-hotfix/ # Hotfix worktree
Or nested:
~/repos/myproject/
├── main/ # Main worktree
├── features/
│ ├── auth/ # Feature worktree
│ └── ui/ # Feature worktree
└── hotfix/ # Hotfix worktree
Beads with Worktrees
When using beads (task tracker) with worktrees, disable the daemon:
export BEADS_NO_DAEMON=1
bd --no-daemon ready
bd --no-daemon create "task"
Common Issues
Branch Already Checked Out
git worktree remove /path/to/other
Stale Worktree References
git worktree prune
git worktree prune --verbose
Shared Resources
Each worktree shares:
.git directory (refs, objects)
- Remote configurations
- Hooks
Each worktree has separate:
- Working directory
- Index (staging area)
- HEAD
Scripts
Create Feature Worktree
#!/bin/bash
FEATURE=$1
BASE=${2:-main}
git worktree add -b feature/$FEATURE ../${PWD##*/}-$FEATURE $BASE
cd ../${PWD##*/}-$FEATURE
npm install
echo "Worktree created at $(pwd)"
Cleanup Old Worktrees
#!/bin/bash
for wt in $(git worktree list --porcelain | grep "^worktree" | cut -d' ' -f2); do
branch=$(git -C "$wt" branch --show-current)
if git branch --merged main | grep -q "$branch"; then
echo "Removing merged worktree: $wt ($branch)"
git worktree remove "$wt"
fi
done
git worktree prune
Best Practices
- Use descriptive paths - Include branch name in directory
- Install dependencies - Run npm/yarn install in each worktree
- Prune regularly - Clean up stale references
- Don't nest worktrees - Keep them sibling directories
- Lock long-running - Prevent accidental pruning
- Separate IDE workspace - Each worktree gets own IDE window
- Disable beads daemon - Prevent database conflicts