Cleaning up merged worktrees

Worktrees pile up: a branch gets merged, a pull request closes, a folder is deleted by hand. The Clean up sheet lists the worktrees that are finished with and removes the ones you tick. Branches always stay.

Where to find it

  • Worktrees tab › Clean up N, shown when any worktree is merged, gone or missing.
  • Sidebar footer › Clean up.
  • Command palette › Remove N merged or gone worktrees…

What counts as finished

A worktree lands in the Merged or gone column, and in the Clean up sheet, when any of these is true:

ReasonHow Mergepond decides
MergedIts branch is in git branch --merged against the default branch (origin/HEAD, else main, master or trunk) and the worktree isn't sitting on the default branch's tip.
Branch gone on the remoteThe branch had an upstream and the upstream no longer exists.
Folder is missingGit still lists the worktree but its folder isn't on disk.

The main folder is never listed, and neither is the worktree open in this window.

The Clean up sheet

The sheet opens with the line "These are merged, their branch is gone from the remote, or their folder is missing. Branches stay." Each row shows:

  • A checkbox. Clean worktrees are ticked by default. Worktrees with uncommitted changes are unticked, and say "N uncommitted changes would be lost".
  • The worktree's name and branch, and the reason it is here.
  • Its size on disk, "no folder" for a missing one, or "unknown size" while it is still being measured.

The footer shows "Frees about size" for the ticked set and the button Remove N worktrees. If every worktree is still in use, the sheet says "Nothing to clean up. Every worktree is still in use."

The Merged or gone column and the Clean up button that opens the sheet.

What happens on remove

Removing is quick to confirm and finishes in the background:

  1. Each card shows "Removing the folder. The branch stays." until the list refreshes.
  2. The folder is moved into the repository's .git/mergepond/trash and deleted from there in the background, so the board updates at once instead of waiting for a large node_modules to go. Worktrees that are locked, contain submodules, live on another disk or belong to a remote repository are removed with git worktree remove instead.
  3. Git's record of the worktree is pruned.
  4. A toast confirms: "Removed the name worktree. The branch is still there." or "Removed N worktrees. Their branches are still there."

Mergepond keeps a worktree, and tells you why, when it has uncommitted or untracked files and you didn't choose to lose them ("It has N uncommitted or untracked files.") or when it is the main worktree ("It's the main worktree, which can't be removed."). A kept worktree shows as an error toast: "Kept name. reason".

Branches are never deleted by clean-up. Delete a branch from Sidebar › Branches if you want it gone too.

Free and Pro

Clean-up is part of the worktree board, which is Pro from Mergepond 1.0.7. On Free, remove worktrees one at a time from the Worktrees list or the sidebar. See Worktree board: Free and Pro.