Overview
Instead of:- Stashing changes
- Switching branches
- Switching back
- Restoring stash
- Create a worktree on another branch
- Work on both simultaneously
- No context switching overhead
Commands
Add Worktree
List Worktrees
Remove Worktree
Prune Stale Entries
Workflow Example
Scenario: Working on Feature, Need to Hotfix
You’re deep in feature development when a critical bug is reported. Without worktrees:Directory Structure
Use Cases
Parallel Development
Testing Branches
Long-running Operations
Code Review
Best Practices
Limitations
- Each branch can only be checked out in one worktree
- The main worktree cannot be removed
- All worktrees share the same
.witdirectory
Worktrees vs Other Approaches
Troubleshooting
Branch already checked out
Branch already checked out
A branch can only be in one worktree:Remove the existing worktree or use a different branch.
Worktree directory exists
Worktree directory exists
Remove or choose a different path:
Stale worktree entries
Stale worktree entries
If you deleted a worktree directory manually: