Work on Parallel Git Branches with Worktrees
8 steps · about 2 h 25 min · Intermediate
- Learn the worktree model (reference, Git, 30 min)
Understand the main worktree, linked worktrees and their shared repository data.
- Create a linked worktree (guide, Git, 20 min)
Add a new directory for an existing or new branch without cloning the repository again.
- Inspect registered worktrees (reference, Git, 15 min)
Read branch, path, lock and prunable state before changing anything.
- Protect a portable worktree (reference, Git, 15 min)
Lock metadata when a worktree lives on a removable or intermittently available filesystem.
- Move a worktree safely (reference, Git, 15 min)
Relocate a linked working directory while keeping Git metadata consistent.
- Remove a finished worktree (reference, Git, 15 min)
Check cleanliness, remove the directory through Git and preserve any branch that still matters.
- Repair moved metadata (reference, Git, 20 min)
Reconnect administrative records after a manual move or a changed main-worktree path.
- Prune stale records (reference, Git, 15 min)
Expire only worktree metadata whose directory is genuinely gone and no longer protected.