| name | worktree |
| description | Manage git worktrees. Use when user wants to create, list, delete, or switch worktrees. Helps with branch-based development workflows where each branch has its own working directory. |
Git Worktree Management
Overview
Git worktrees create isolated working directories that share the same repository. Work on multiple branches simultaneously without stashing or switching.
Announce at start: "I'm using the worktree skill to manage git worktrees."
Quick Commands
git worktree add .worktrees/<name> -b <branch-name>
git worktree add .worktrees/<name> <existing-branch>
git worktree list
git worktree remove .worktrees/<name>
git worktree prune
Recommended Directory Structure
project/
├── .worktrees/ # Hidden, keeps project root clean
│ ├── feature-auth/ # Worktree for auth feature
│ ├── bugfix-login/ # Worktree for login fix
│ └── experiment-new-ui/ # Experimental work
├── .gitignore # Must include .worktrees/
└── ... (main working tree)
Why .worktrees/:
- Hidden (starts with dot)
- Project-local (easy to find)
- Clear naming convention
Setup Workflow
1. Detect Current Location
git rev-parse --is-inside-work-tree
git worktree list | grep "$(pwd)"
git rev-parse --show-toplevel
2. Verify .gitignore
CRITICAL: Before creating worktrees, ensure .worktrees/ is in .gitignore:
grep -q "^\.worktrees/$" .gitignore && echo "OK" || echo "MISSING"
echo ".worktrees/" >> .gitignore
git add .gitignore
git commit -m "chore: add .worktrees to gitignore"
3. Create Worktree
mkdir -p .worktrees
git worktree add .worktrees/<name> -b <branch-name>
git worktree add .worktrees/<name> -b <branch-name> origin/main
git fetch origin
git worktree add .worktrees/<name> origin/<branch-name>
4. Post-Creation Setup
Each worktree needs its own setup:
cd .worktrees/<name>
yarn install
npx nuxt prepare
pip install -r requirements.txt
cargo build
Common Operations
List All Worktrees
git worktree list
Switch to Worktree
cd .worktrees/<name>
Remove Worktree
git worktree remove .worktrees/<name>
git worktree remove --force .worktrees/<name>
git worktree remove .worktrees/<name>
git branch -d <branch-name>
Clean Up Stale References
git worktree prune
git worktree prune --dry-run
Move Worktree
git worktree move .worktrees/<old-name> .worktrees/<new-name>
Branch Naming Conventions
| Prefix | Use Case | Example |
|---|
feature/ | New features | feature/user-auth |
bugfix/ | Bug fixes | bugfix/login-crash |
hotfix/ | Urgent fixes | hotfix/security-patch |
experiment/ | Experimental work | experiment/new-ui |
refactor/ | Code refactoring | refactor/api-cleanup |
Worktree directory mirrors branch:
- Branch:
feature/user-auth
- Worktree:
.worktrees/feature-user-auth
Integration with Development
Starting Feature Work
git worktree add .worktrees/feature-x -b feature/x origin/main
cd .worktrees/feature-x
yarn install
npx nuxt prepare
yarn test
Finishing Feature Work
git push -u origin feature/x
cd /path/to/main/repo
git worktree remove .worktrees/feature-x
git branch -d feature/x
Parallel Development
Work on multiple features simultaneously:
cd .worktrees/feature-a
yarn dev --port 3001
cd .worktrees/feature-b
yarn dev --port 3002
yarn dev --port 3000
Troubleshooting
"fatal: '' is a worktree but..."
Branch is already checked out:
git worktree list | grep <branch-name>
"fatal: '' is already checked out"
git worktree add .worktrees/<name> -b <new-branch-name>
Worktree shows wrong branch
cd .worktrees/<name>
git status
git branch
git worktree remove .worktrees/<name>
git worktree add .worktrees/<name> -b <branch>
node_modules issues
Each worktree needs its own node_modules:
cd .worktrees/<name>
rm -rf node_modules
yarn install
.nuxt not generating types
cd .worktrees/<name>
rm -rf .nuxt
npx nuxt prepare
Quick Reference
| Task | Command |
|---|
| Create (new branch) | git worktree add .worktrees/<name> -b <branch> |
| Create (existing branch) | git worktree add .worktrees/<name> <branch> |
| List | git worktree list |
| Remove | git worktree remove .worktrees/<name> |
| Prune stale | git worktree prune |
| Move | git worktree move <old> <new> |
| Check if in worktree | git rev-parse --show-toplevel |
Red Flags
Never:
- Create worktrees without
.worktrees/ in .gitignore
- Share
node_modules between worktrees
- Check out same branch in multiple worktrees
- Leave stale worktrees (prune regularly)
Always:
- Use
.worktrees/ directory (or ask user preference)
- Run project setup after creating worktree
- Verify baseline tests pass
- Clean up worktrees after merging PRs