| name | git-worktrees |
| description | Use when working on multiple features simultaneously. Creates isolated workspaces without branch switching, enabling parallel development. |
Git Worktrees
Core Principle
Work on multiple features in parallel using git worktrees instead of constantly switching branches.
When to Use This Skill
- Working on multiple features simultaneously
- Need to quickly switch context without stashing
- Want to run tests on one branch while working on another
- Comparing implementations across branches
- Client requests urgent fix while working on feature
What Are Git Worktrees?
Git worktrees allow you to have multiple working directories for the same repository, each checked out to a different branch.
Traditional way:
git checkout feature-a
[work on feature-a]
git stash
git checkout feature-b
[work on feature-b]
git stash
git checkout feature-a
git stash pop
With worktrees:
cd ../project-feature-a
cd ../project-feature-b
cd ../project-hotfix
Benefits
✅ No stashing: Changes stay in their worktree
✅ Parallel work: Different features in different terminals
✅ Independent testing: Test one branch while coding another
✅ Quick context switching: Just cd to different directory
✅ Clean state: Each worktree is independent
Git Worktree Basics
Creating a Worktree
git worktree add <path> <branch>
git worktree add ../project-feature-x feature/feature-x
git worktree add -b feature/new-feature ../project-new-feature main
git worktree add ../project-hotfix -b hotfix/security-patch main
Listing Worktrees
git worktree list
Removing a Worktree
git worktree remove ../project-feature-x
git worktree prune
Moving Between Worktrees
cd ../project-auth
cd ../project-api
cd ../project
Worktree Workflow Examples
Example 1: Parallel Feature Development
Scenario: Working on authentication (long-term) and need to add quick bug fix
cd ~/projects/myapp
git checkout main
git worktree add -b feature/authentication ../myapp-auth main
cd ../myapp-auth
[make changes, run tests, commit]
cd ~/projects/myapp
git worktree add -b fix/urgent-bug ../myapp-bugfix main
cd ../myapp-bugfix
[fix bug, test, commit, push]
gh pr create --title "fix: resolve urgent bug"
git worktree remove ../myapp-bugfix
cd ../myapp-auth
[continue work...]
Example 2: Testing Across Branches
Scenario: Need to compare behavior between main and your feature branch
cd ~/projects/myapp
git worktree add -b feature/new-api ../myapp-feature main
cd ../myapp-feature
[implement feature]
./scripts/safe-test.sh npm test
cd ~/projects/myapp
./scripts/safe-test.sh npm test
Example 3: Code Review Workflow
Scenario: Reviewing a PR while working on your own feature
cd ~/projects/myapp-my-feature
[your work...]
cd ~/projects/myapp
git fetch origin
git worktree add ../myapp-review-pr123 pr-123
cd ../myapp-review-pr123
[review code, run tests, check functionality]
gh pr review 123 --comment -b "LGTM! Tested locally, works great."
cd ~/projects/myapp
git worktree remove ../myapp-review-pr123
cd ../myapp-my-feature
[continue working...]
Worktree Organization Strategies
Strategy 1: Sibling Directories
~/projects/
├── myapp/ # Main worktree (main branch)
├── myapp-auth/ # feature/authentication
├── myapp-api/ # feature/api-refactor
└── myapp-bugfix/ # fix/login-error
Pros: Easy to see all worktrees, simple paths
Cons: Clutters parent directory
Strategy 2: Subdirectory Organization
~/projects/myapp/
├── .git/ # Main repo
├── main/ # Main branch worktree
├── worktrees/
│ ├── auth/ # feature/authentication
│ ├── api/ # feature/api-refactor
│ └── bugfix/ # fix/login-error
Pros: Organized, all in one place
Cons: Slightly longer paths
Strategy 3: Feature-Based Structure
~/projects/myapp/
├── .git/
├── production/ # main branch
├── staging/ # staging branch
├── features/
│ ├── authentication/
│ ├── api-refactor/
│ └── user-profile/
└── fixes/
├── login-error/
└── memory-leak/
Pros: Very organized, clear purpose
Cons: More complex setup
Worktree Best Practices
DO:
✅ Name worktree directories clearly (match branch name)
✅ Remove worktrees after branch is merged
✅ Run git worktree prune periodically
✅ Use worktrees for truly parallel work
✅ Keep worktrees in predictable locations
DON'T:
❌ Create too many worktrees (keep it manageable)
❌ Leave stale worktrees around after branches merged
❌ Use worktrees for trivial branch switches
❌ Forget which worktree you're in (use git prompt)
Worktree Cleanup
Removing Merged Worktrees
git worktree remove ../myapp-feature
git branch -d feature/feature-name
git worktree prune
Finding Stale Worktrees
git worktree list
git branch --merged
for worktree in $(git worktree list --porcelain | grep worktree | cut -d' ' -f2); do
cd $worktree
branch=$(git branch --show-current)
if git branch --merged main | grep -q "$branch"; then
echo "Removing merged worktree: $worktree"
git worktree remove $worktree
fi
done
Integration with Skills
Use with:
dispatching-parallel-agents - Run multiple agents in different worktrees
git-workflow - Standard git practices apply in each worktree
executing-plans - Execute different plans in parallel
code-review - Review PRs in separate worktrees
Workflow:
- Create worktree for feature:
git worktree add
- Work on feature: Use
brainstorming, writing-plans, executing-plans
- Test in worktree: Use
database-backup for each worktree
- Review in main worktree: Compare implementations
- Merge and cleanup: Remove worktree
Common Issues and Solutions
Issue 1: Worktree Creation Fails
Error: fatal: 'path' already exists
Solution:
rm -rf ../myapp-feature
git worktree add ../myapp-feature feature/feature-name
git worktree add ../myapp-feature-v2 feature/feature-name
Issue 2: Branch Checked Out in Another Worktree
Error: fatal: 'branch' is already checked out at 'path'
Solution:
git worktree remove path/to/existing/worktree
git worktree add -b feature/feature-name-v2 ../myapp-feature feature/feature-name
Issue 3: Forgot Which Worktree You're In
Solution:
pwd
git branch --show-current
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
PS1="\w \$(parse_git_branch) $ "
Issue 4: Stale Worktree References
Error: Worktree listed but directory doesn't exist
Solution:
git worktree prune -v
git worktree remove --force path/to/worktree
Advanced Worktree Usage
Worktrees for CI/CD Testing
git worktree add ../myapp-ci-test feature/feature-name
cd ../myapp-ci-test
./scripts/safe-test.sh npm run ci-test
cd -
git worktree remove ../myapp-ci-test
Worktrees for Deployment Branches
git worktree add ../myapp-production production
git worktree add ../myapp-staging staging
cd ../myapp-production
git pull origin production
[run deployment script]
cd ../myapp-staging
git pull origin staging
[run staging deployment]
Worktree Checklist
Before creating worktree:
While working in worktree:
After finishing work:
Authority
This skill is based on:
- Git worktrees feature (since Git 2.5)
- Professional development: Parallel work is common
- Efficiency: Context switching is expensive
- Best practices from the Superpowers framework
Social Proof: Many professional developers use worktrees for parallel feature development.
Your Commitment
Before using worktrees:
Bottom Line: Worktrees enable true parallel development. Use them when you need to work on multiple features simultaneously without constant branch switching. Clean up when done.