| name | git-worktree |
| version | 1.0.0 |
| description | Manage Git worktrees for parallel development workflows without switching branches |
Git Worktree Management
Efficiently work on multiple branches simultaneously using Git worktrees.
When to Use
Use this skill when:
- Working on multiple features simultaneously
- Reviewing PRs while working on a feature
- Need to test something on another branch
- Hotfixing production while developing
- Comparing branches side-by-side
What Are Worktrees?
Git worktrees allow you to checkout multiple branches at the same time in different directories.
main project/
├── .git (repository)
├── src/ (main branch)
└── ...
../project-feature-a/ (worktree for feature-a branch)
├── .git (file pointing to main repo)
├── src/
└── ...
../project-hotfix/ (worktree for hotfix branch)
├── .git (file pointing to main repo)
├── src/
└── ...
Benefits:
- No need to stash or commit incomplete work
- Instant branch switching (just cd to directory)
- Each worktree has its own build artifacts
- Can run different versions simultaneously
Basic Commands
Create Worktree
git worktree add ../project-feature-a -b feature-a
git worktree add ../project-hotfix hotfix-branch
git worktree add ../project-debug abc123
git worktree add --detach ../project-temp
List Worktrees
git worktree list
Remove Worktree
git worktree remove ../project-feature-a
git worktree remove --force ../project-feature-a
git worktree prune
Move Worktree
git worktree move ../project-feature-a ../new-location
Workflow Patterns
Pattern 1: Feature Development
cd ~/projects/myproject
git checkout main
git worktree add ../myproject-feature-a -b feature-a
cd ../myproject-feature-a
cd ~/projects/myproject
cd ../myproject-feature-a
git push origin feature-a
cd ~/projects/myproject
git pull
git worktree remove ../myproject-feature-a
Pattern 2: PR Review
cd ~/projects/myproject-feature-a
git worktree add ../myproject-pr-123 pr-123
cd ../myproject-pr-123
cd ~/projects/myproject-feature-a
git worktree remove ../myproject-pr-123
Pattern 3: Hotfix During Development
cd ~/projects/myproject-feature-complex
git worktree add ../myproject-hotfix -b hotfix-urgent origin/main
cd ../myproject-hotfix
git commit -m "Fix critical production issue"
git push origin hotfix-urgent
cd ~/projects/myproject-feature-complex
git worktree remove ../myproject-hotfix
Pattern 4: Comparing Branches
git worktree add ../myproject-v1 v1.0
git worktree add ../myproject-v2 v2.0
cd ../myproject-v1
./run-server.sh --port 8001 &
cd ../myproject-v2
./run-server.sh --port 8002 &
git worktree remove ../myproject-v1
git worktree remove ../myproject-v2
Advanced Usage
Shared Configuration
Worktrees share the same .git directory, which means:
✅ Shared:
- Git configuration
- Hooks (pre-commit, etc.)
- Refs (branches, tags)
❌ Not Shared:
- Working directory files
- Index (staging area)
- Build artifacts
- IDE settings
IDE Setup
Each worktree can have its own IDE instance:
cd ../myproject-feature-a
code . --user-data-dir=/tmp/vscode-feature-a
cd ../myproject-feature-a
idea .
Build Artifacts
Build artifacts don't conflict:
cd ~/projects/myproject
cargo build --release
ls target/release/myproject
cd ../myproject-feature-a
cargo build --release
ls target/release/myproject
Gitignore for Worktrees
Add to .gitignore:
# Ignore other worktree directories
../project-*/*.log
../project-*/target/
../project-*/node_modules/
Best Practices
Naming Convention
git worktree add ../myproject-feature-auth -b feature/auth
git worktree add ../myproject-fix-logging -b fix/logging
git worktree add ../myproject-review-pr-456 origin/pr/456
git worktree add ../temp1 -b x
git worktree add ../test -b y
Directory Structure
~/projects/
├── myproject/
├── myproject-feature-a/
└── myproject-hotfix/
~/projects/myproject/
├── .git/
├── src/
├── worktrees/
│ ├── feature-a/
│ └── hotfix/
└── ...
~/worktrees/
├── myproject-main/
├── myproject-feature-a/
└── myproject-hotfix/
Cleanup Schedule
git worktree prune
git worktree list --porcelain
for wt in $(git worktree list --porcelain | grep '^worktree' | cut -d' ' -f2); do
if [ ! -d "$wt" ]; then
echo "Pruning deleted worktree: $wt"
git worktree prune
break
fi
done
Common Scenarios
Scenario: Multiple Active Features
git worktree add ../project-feature-a -b feature-a
git worktree add ../project-feature-b -b feature-b
git worktree add ../project-fix-a -b fix/feature-a-a-issue
cd ../project-feature-a
cd ../project-feature-b
cd ../project-fix-a
cd ../project-feature-a
git merge fix/feature-a-a-issue
git push
git worktree remove ../project-fix-a
git worktree remove ../project-feature-a
Scenario: Benchmarking
git worktree add ../project-baseline v1.0
git worktree add ../project-optimized optimized-branch
cd ../project-baseline
cargo bench --bench my_benchmark > baseline.txt
cd ../project-optimized
cargo bench --bench my_benchmark > optimized.txt
diff baseline.txt optimized.txt
git worktree remove ../project-baseline
git worktree remove ../project-optimized
Troubleshooting
Worktree Already Exists
git worktree add ../project-feature-a feature-a
git worktree list
git worktree remove /path/to/existing/worktree
Untracked Files in Worktree
cd ../project-feature-a
git add .
git stash
git worktree remove --force ../project-feature-a
Branch Already Exists
git worktree add ../project-feature-a feature-a
git worktree add ../project-feature-a-v2 -b feature-a-v2
Detached HEAD
cd ../project-temp
git status
git checkout -b new-branch-name
git checkout main
Integration with Kilo
This skill integrates with Kilo's workflow:
- Parallel Work: Switch between tasks without stashing
- Evidence: Compare branches with file:line references
- Minimal Context: Each worktree has focused scope
- Clean Workflow: No incomplete commits just to switch
Use with other skills:
- systematic-debugging: Create worktree for debugging
- code-review: Review PRs in separate worktree
- test-driven-development: Test different implementations
Quick Reference
git worktree add <path> <branch>
git worktree add <path> -b <new-branch>
git worktree list
git worktree list --porcelain
git worktree remove <path>
git worktree remove --force <path>
git worktree prune
git worktree move <old-path> <new-path>
git worktree lock <path>
git worktree unlock <path>