wit worktree command lets you check out multiple branches simultaneously in separate directories. This is useful when you need to work on different branches without constantly switching.
Overview
- Work on a feature while also working on a hotfix
- Compare different branches side by side
- Run tests on one branch while developing on another
- Avoid stashing/committing in-progress work when switching contexts
Commands
add
Create a new worktree for a branch.Arguments
Examples
Example Output
list
List all worktrees for the repository.Example Output
remove
Remove a worktree.Arguments
Examples
prune
Remove stale worktree entries.Example Output
Use Cases
Hotfix While Developing
You’re working on a feature when an urgent bug needs fixing:Side-by-Side Comparison
Compare code across branches:Run Tests While Developing
Run tests on one branch while continuing to develop:Code Review
Review a colleague’s PR without switching branches:Best Practices
Use sibling directories
Use sibling directories
Keep worktrees as siblings to your main project:This keeps them organized and easy to find.
Name worktrees descriptively
Name worktrees descriptively
Use clear names that indicate purpose:
Clean up when done
Clean up when done
Remove worktrees you’re no longer using:
Don't forget about them
Don't forget about them
Periodically check for forgotten worktrees:Old worktrees take up disk space and can be confusing.
How Worktrees Work
Shared Objects
All worktrees share the same.wit (or .git) directory:
- Objects, refs, and history are shared (saves disk space)
- Commits made in any worktree are immediately visible to all
- Each worktree has its own index and HEAD
Linked vs Main Worktree
- Main worktree: The original directory where you cloned/initialized
- Linked worktrees: Additional worktrees created with
wit worktree add
wit worktree remove.
Comparison with Other Approaches
Troubleshooting
Branch is already checked out
Branch is already checked out
If you see “fatal: ‘branch’ is already checked out”:A branch can only be checked out in one worktree at a time.
Worktree directory exists
Worktree directory exists
If the target directory already exists:
Stale worktree after manual deletion
Stale worktree after manual deletion
If you deleted a worktree directory manually:
Uncommitted changes in worktree
Uncommitted changes in worktree
If
wit worktree remove fails due to uncommitted changes:Related Commands
wit switch- Switch branches in current worktreewit stash- Temporarily save changeswit clone- Clone a repository