Housekeeping Commands
Worktrees create entries in Git's internal database (inside .git/worktrees/). Simply deleting the folder with rm -rf leaves a stale entry — Git will think the worktree still exists but is "broken." Always use Git's own commands to manage the lifecycle.
| Command | Purpose |
|---|---|
git worktree list |
Show all active worktrees, their paths, and checked-out branches |
git worktree add <path> -b <branch> |
Create a new worktree with a new branch |
git worktree add <path> <existing-branch> |
Check out an existing branch into a new worktree |
git worktree move <path> <new-path> |
Relocate a worktree directory (updates Git's internal record) |
git worktree remove <path> |
Safely remove a worktree and its Git metadata |
git worktree prune |
Garbage-collect stale entries for worktrees whose directories no longer exist |
git worktree lock <path> |
Prevent a worktree from being auto-pruned (useful for worktrees on removable drives) |
The Stale Entry Problem
If you rm -rf a worktree directory without running git worktree remove or git worktree prune, subsequent git worktree list calls will show the path as prunable. Running git worktree prune cleans these up. In CI environments where worktrees are created and destroyed programmatically, adding git worktree prune to your cleanup scripts is essential.