Skip to main content
Worktrees let you have multiple working directories for the same repository, each on a different branch.

Overview

Instead of:
  • Stashing changes
  • Switching branches
  • Switching back
  • Restoring stash
You can:
  • Create a worktree on another branch
  • Work on both simultaneously
  • No context switching overhead

Commands

Add Worktree

Examples:

List Worktrees

Output:

Remove Worktree

Example:

Prune Stale Entries

Removes worktree entries where the directory no longer exists.

Workflow Example

Scenario: Working on Feature, Need to Hotfix

You’re deep in feature development when a critical bug is reported. Without worktrees:
With worktrees:

Directory Structure

Use Cases

Parallel Development

Testing Branches

Long-running Operations

Code Review

Best Practices

Use consistent namingName worktrees clearly:
Clean up when doneDon’t leave worktrees lying around:
Share node_modules (optional)For JavaScript projects, symlink node_modules:

Limitations

  • Each branch can only be checked out in one worktree
  • The main worktree cannot be removed
  • All worktrees share the same .wit directory

Worktrees vs Other Approaches

Troubleshooting

A branch can only be in one worktree:
Remove the existing worktree or use a different branch.
Remove or choose a different path:
If you deleted a worktree directory manually: