🔀 Git: Fix a Worktree Blocking a Branch Delete It Doesn’t Need
Git refuses to delete any branch that’s checked out in any linked worktree, not just the one you’re currently sitting in. A worktree created months ago for a quick hotfix, and then simply abandoned without running git worktree remove, still holds that branch checked out as far as Git is concerned — so a plain git branch -d fails with a message that often doesn’t even mention the forgotten worktree’s path.
🔎 The Problem
git branch -d feature/old-hotfix # error: cannot delete branch 'feature/old-hotfix' checked out at # '/home/dev/worktrees/hotfix-review' ls /home/dev/worktrees/ # hotfix-review <- abandoned weeks ago, forgot it existed
✅ Fix: Clean Up the Worktree, Then Delete the Branch
- Run
git worktree listfirst to see every linked worktree and which branch each one has checked out — this is the fastest way to find the one actually blocking your delete. - Remove the abandoned worktree properly with
git worktree remove <path>(add--forceif it has uncommitted changes you’ve confirmed are safe to discard) instead of just deleting its folder by hand, which leaves Git’s own metadata pointing at a directory that no longer exists. - Run
git worktree pruneperiodically if worktrees tend to get abandoned on a team — it clears administrative files for worktrees whose directories are already gone, preventing this exact confusion from recurring.
🚨 Why This Is Dangerous
- Manually deleting a worktree’s folder with
rm -rfinstead ofgit worktree removeleaves stale metadata under.git/worktrees/that can make the branch appear permanently ‘checked out’ to Git even though nothing on disk uses it anymore, requiring a manual prune to untangle.
A worktree you forgot about hasn’t forgotten you — as far as Git is concerned, it’s still holding that branch open.




