Work on Parallel Git Branches with Worktrees

8 steps · about 2 h 25 min · Intermediate

  1. Learn the worktree model (reference, Git, 30 min)

    Understand the main worktree, linked worktrees and their shared repository data.

  2. Create a linked worktree (guide, Git, 20 min)

    Add a new directory for an existing or new branch without cloning the repository again.

  3. Inspect registered worktrees (reference, Git, 15 min)

    Read branch, path, lock and prunable state before changing anything.

  4. Protect a portable worktree (reference, Git, 15 min)

    Lock metadata when a worktree lives on a removable or intermittently available filesystem.

  5. Move a worktree safely (reference, Git, 15 min)

    Relocate a linked working directory while keeping Git metadata consistent.

  6. Remove a finished worktree (reference, Git, 15 min)

    Check cleanliness, remove the directory through Git and preserve any branch that still matters.

  7. Repair moved metadata (reference, Git, 20 min)

    Reconnect administrative records after a manual move or a changed main-worktree path.

  8. Prune stale records (reference, Git, 15 min)

    Expire only worktree metadata whose directory is genuinely gone and no longer protected.