How to remove a git worktree (and fix the errors)

Remove a git worktree with git worktree remove, clean up folders you deleted by hand with prune, and fix "cannot delete branch used by worktree", locked and "contains modified" errors.

Short answer: run git worktree remove <path> to delete a worktree, then git branch -d <branch> if you no longer need its branch. If you already deleted the folder by hand, run git worktree prune. git refuses to remove a worktree that has uncommitted or untracked files, or one that is locked, and it won’t delete a branch while a worktree still has it checked out.

The normal way

git worktree list                 # find the path
git worktree remove ../app-search # delete the worktree directory
git branch -d feat/search         # delete the branch, if it's merged

Removing a worktree never deletes its branch or commits. Those stay in the repository until you delete the branch yourself.

Fixing the common errors

error: cannot delete branch 'feat' used by worktree at '…'

You tried git branch -d or -D on a branch that a worktree still has checked out. Remove the worktree first, then delete the branch:

git worktree remove ../app-search
git branch -d feat/search

If the worktree’s folder is already gone, git still thinks the branch is checked out there. Running git worktree list -v shows that worktree as prunable. Run git worktree prune and the branch is free to delete.

fatal: '…' contains modified or untracked files, use --force to delete it

The worktree has changes that would be lost. Look before you force:

git -C ../app-search status --short

Commit or stash what you want to keep, then remove it normally. git worktree remove --force deletes those files permanently. They were never committed, so there is no reflog to get them back from.

fatal: cannot remove a locked working tree, lock reason: …

Someone locked the worktree, often a tool or AI agent that is still using it. Claude Code, for example, locks the worktrees it creates while a session runs. Make sure nothing is working there, then:

git worktree unlock ../app-search
git worktree remove ../app-search

git also suggests remove -f -f, which removes a locked worktree in one step. Only use it when you know what’s inside.

fatal: '.' is a main working tree

The main working tree is your original clone, and it can’t be removed with git worktree remove. To get rid of the whole repository, delete the directory itself.

fatal: 'feat' is already used by worktree at '…'

This isn’t a removal error, but it usually comes up in the same cleanup: you tried to check out a branch that another worktree has. Either work in that worktree, or remove it first.

If you deleted the folder with rm -rf or Finder

git worktree prune --dry-run -v   # see what would be cleaned
git worktree prune -v

Deleting the directory doesn’t tell git. Its bookkeeping in .git/worktrees/ stays behind, and the branch counts as checked out. prune removes the records of worktrees whose directories no longer exist. It doesn’t touch real worktrees, branches or commits.

Removing many worktrees at once

A loop over git worktree list --porcelain can remove everything except the main checkout, but don’t do that blindly. Each worktree may hold uncommitted work, commits that were never pushed, or a branch whose pull request was squash-merged, which git branch --merged won’t detect. Go through the six checks in our cleanup checklist before you delete in bulk.

Orchard runs those checks for every worktree on your Mac and lists the ones already in main with the reason, such as “PR #142 merged 3 days ago”. Cleanup snapshots uncommitted files and the branch tip first, so you can restore it for 7 days. Worktrees with a running agent are never touched.

FAQ

Does git worktree remove delete the branch?

No. git worktree remove deletes only the worktree directory and git’s record of it. The branch and its commits stay in the repository; delete the branch separately with git branch -d, or -D if it was squash-merged.

What is the difference between git worktree remove and prune?

remove deletes a worktree that still exists on disk, checking for unsaved work first. prune only cleans up git’s records of worktrees whose directories are already gone, for example after rm -rf.

Why does git say my branch is used by a worktree I already deleted?

Because the folder was deleted without telling git, so its record in .git/worktrees still exists. Run git worktree prune to remove the stale record, and the branch can be deleted or checked out again.