Git Cheat Sheet · Worktrees

Clean up a missing worktree

git worktree prune

If a worktree's folder was deleted or moved outside of git, the repository keeps its reference and its branch is still considered checked out. git worktree prune removes references whose folder no longer exists.

What it does

If the folder was deleted or moved outside git, the repository keeps its reference and its branch is still considered checked out. This reference must be removed.

A use case

You erased the folder with your file manager: git still considers its branch checked out as long as the reference exists.

On the command line

git worktree prune --dry-run --verbose
Shows what would be removed, without changing anything.
git worktree prune
Removes the references of missing folders.
git worktree repair <folder>
Restores the link if the folder was simply moved by hand.

In Merathon

  1. The worktree appears with the note "not found" in the "Worktrees" section.
  2. Right-click → "Remove from list…": only the reference is removed, the branch remains.

Frequently asked questions

Does the command touch my branch?

No: only the worktree's reference is removed. The branch and its commits stay, and the branch can be checked out again.

Could my worktree on an external drive get cleaned up?

Yes, if the drive is unplugged at the time of the cleanup. git worktree lock <folder> protects it.

See also