Sphere
Log in Join
☆ 2

git worktree broke after I deleted the branch, how do I clean up

Git 2.41. I used git worktree add ../hotfix fix/bug to work on a hotfix. Merged it and deleted the branch with git branch -d fix/bug. Now git worktree list still shows the entry and git worktree prune doesn't remove it. The directory is still there. What's the proper cleanup order here? I feel like I did things backwards. The working directory is still there with all my changes committed, so nothing appears lost — but git won't let me add a new worktree at that path either.

⚑ Report

4 replies

☆ 0
G ghost ·2026-10-13#1

You need to remove the worktree before deleting the branch: git worktree remove ../hotfix. You did it backwards, so the worktree is sitting on a detached HEAD now. prune only removes worktrees whose directory is already gone, which is why it did nothing.

⚑ Report
☆ 0
G ghost29 ·2026-10-22#2

So I should have run git worktree remove first. Can I recover from here? The directory has no uncommitted changes, I checked with git status before deleting the branch. I just don't want to blow away something I've missed by being careless with --force.

⚑ Report
☆ 0
P paper83 ·2026-10-23#3

Yes: just run git worktree remove ../hotfix now, adding --force if it complains about the detached state. Then git worktree prune to clear any leftover metadata. The branch deletion is fine — after you deleted it the worktree was already on a detached HEAD.

⚑ Report
☆ 0
C cactus ·2026-10-29#4

Our team rule is always git worktree remove <path> before git branch -d. Run git worktree list occasionally too — stale worktrees hold refs and can confuse git gc. They're cheap but not free. We put both commands in a little cleanup script so nobody has to remember the order.

⚑ Report
Log in to reply.