Skip to content
WorktreeWise
#git#troubleshooting#branches#worktree

Cannot delete branch because of worktree

W

WorktreeWise Engineering Team

Updated Sep 2026•5 min read
⚡

TL;DR: The 30-Second Summary

Git blocks `git branch -d` or `git branch -D` if the target branch is currently active in any linked worktree. Locate the worktree with `git worktree list`, switch that worktree to a different branch or remove the worktree, and then delete the branch.

The Real-Life Scenario

“Alex merges a pull request on GitHub and runs branch cleanup locally: `git branch -d feature/billing`. Git aborts: `fatal: Cannot delete branch 'feature/billing' checked out at '/projects/wt-billing'`. Alex forgot that their secondary worktree is still parked on that branch.”

In a standard Git clone, you can only have one branch checked out at a time. In a worktree setup, multiple branches are actively checked out across different directories. Git strictly prevents deleting any branch that currently serves as a worktree's `HEAD`.

Why Git Protects Checked-Out Branches

If Git allowed you to delete a branch currently checked out in a worktree, that worktree would immediately enter an invalid zombie state where its `HEAD` points to a non-existent ref in `refs/heads/`.

What you see in the terminal:

terminal output
$ git branch -d feature/billing
fatal: Cannot delete branch 'feature/billing' checked out at '/projects/wt-billing'
🔍

Under the Hood: Git Plumbing & Architecture

When `git branch -d` runs, Git iterates over all entries in `.git/worktrees/` and reads their `HEAD` files. If any `HEAD` contains `ref: refs/heads/<branch>`, the deletion is aborted with `fatal: Cannot delete branch`.

Quick Command Recipes

Copy and adapt these commands directly in your terminal:

Option A: Remove the worktree if finished

Deletes the worktree directory and its registration, freeing the branch for immediate deletion.

bash
git worktree remove /projects/wt-billing
git branch -d feature/billing

Option B: Switch the worktree to another branch

Rebinds the worktree to `main`, releasing the target branch without deleting the directory.

bash
git -C /projects/wt-billing switch main
git branch -d feature/billing
TUTORIAL

Step-by-Step Practical Walkthrough

Follow these verified steps to safely resolve the issue and guarantee that your filesystem and Git references are in sync.

1

Identify which worktree is using the branch

Run `git worktree list` to see all active branch assignments.

terminal
git worktree list
Expected Output:
/projects/main        04e3a1f [main]
/projects/wt-billing  7b19dc2 [feature/billing]
2

Decide: Retire or Reassign the worktree

If the feature is complete and merged, remove the worktree entirely.

terminal
git worktree remove /projects/wt-billing
3

Delete the branch cleanly

Now that no worktree is holding the branch, delete it safely.

terminal
git branch -d feature/billing
Expected Output:
Deleted branch feature/billing (was 7b19dc2).

Edge Cases & Advanced Scenarios

The worktree folder was already deleted manually

If the folder is gone but Git still blocks deletion, run `git worktree prune` first to clear the ghost checkout.

bash
git worktree prune
git branch -d feature/billing
⚠️

Common Mistakes to Avoid

❌ Mistake: Trying to force delete with `-D` without freeing the worktree

Why it causes trouble: `git branch -D` also fails with the exact same error: force flag does not override worktree checkout safety.

What to do instead: You must switch or remove the worktree first.

✓

Verification Checklist

  • ✓`git branch` no longer lists the deleted branch
  • ✓`git worktree list` confirms no worktree is pointing to the deleted ref
💡

Senior Engineering Tips

  • ★In WorktreeWise, deleting a worktree offers an optional checkbox: 'Also delete local branch', completing both steps in a single click.

Key Takeaways

  • 01.No branch can be deleted while checked out in any active worktree.
  • 02.`git branch -D` cannot bypass this protection.
  • 03.Either remove the worktree or switch it to another branch before deleting.
TOOL

How WorktreeWise Solves This Visually

WorktreeWise eliminates the manual friction and mental overhead of CLI flags. It displays real-time branch states, uncommitted modifications, active terminals, and lock statuses across all worktrees on a single visual dashboard.

WorktreeWise interface showing worktree deletion with optional branch cleanup
WorktreeWise interface showing worktree deletion with optional branch cleanup
W

WorktreeWise Engineering Publication

Written and curated by the core WorktreeWise team. We build developer tools that turn Git worktrees, workflows, and parallel AI coding agents into second nature.

Related Troubleshooting Guides

View all troubleshooting →