Skip to main content
🛡️ Verified Technical Content: Written by Serhii Hrekov. | Last reviewed & updated in Git: July 21, 2026

How to Fix 'fatal: cannot delete branch used by worktree' in Git

· 6 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

Git provides safeguards to protect your active code branches from accidental deletion. When you try to delete a branch and receive the error: fatal: cannot delete branch 'xyz' used by worktree at '/path/to/folder', Git is warning you that the branch is currently checked out and actively linked to another working directory on your machine.

Here is why this error occurs, how to resolve it using three different methods, and how to use the listing commands to manage your workspace.


What is a Git Worktree?

The git worktree feature allows you to have multiple branches checked out at the same time in different physical folders on your computer, all sharing a single .git history.

Normally, Git prevents you from deleting the branch you are currently on. With worktrees, Git extends this protection to any branch currently checked out in any of your other linked worktree folders.


How to Fix the Branch Deletion Error

Depending on whether you still need the folder associated with that worktree, choose one of the following methods to resolve the error.

Method 1: Remove the Worktree Safely

If you are done with the working directory and the branch, dismantle the worktree:

  1. List your active worktrees to locate the path:
    git worktree list
  2. Remove the worktree using the path shown in the list:
    git worktree remove /path/to/worktree/folder
  3. Delete the branch:
    git branch -d your-branch-name

Method 2: Prune Manually Deleted Folders

If you bypassed Git commands and deleted the worktree directory using your file explorer or moved it to the trash, the internal .git index still thinks it exists. You need to clean up these stale links:

  1. Prune the dead worktrees:
    git worktree prune
    (This tells Git to verify if the worktree paths exist on your hard drive, clearing out any missing directories).
  2. Force delete the branch:
    git branch -D your-branch-name

Method 3: Keep the Folder, Switch the Active Branch

If you want to keep the directory but free up the branch so you can delete it, switch to a different branch in that worktree directory:

  1. Navigate to the worktree folder:
    cd /path/to/worktree/folder
  2. Checkout a different branch:
    git checkout main
  3. Return to your main repository directory and delete the branch:
    git branch -d your-branch-name

Auditing and Listing Worktrees

To prevent getting lost in your directories, you can audit your linked branches at any time.

Reading git worktree list Output

git worktree list

The output displays lines containing: /Users/dev/project a1b2c3d [main]

  • Path: The absolute location of the worktree directory on your machine.
  • Commit Hash: The current commit checked out in that folder.
  • Branch: The name of the active branch inside the brackets.

Advanced Listing Flags

  • Porcelain Mode (--porcelain): Outputs data in key-value pairs, which is ideal for scripts and shell automation:
    git worktree list --porcelain
  • Verbose Mode (-v): Shows additional details, such as whether a worktree is locked (which prevents it from being pruned or deleted):
    git worktree list -v

Command Reference

ActionCommand
Audit all active foldersgit worktree list
Dismantle worktree directorygit worktree remove <path>
Clean up dead linksgit worktree prune
Porcelain outputgit worktree list --porcelain
Show locked statusgit worktree list -v

Sources