Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio
Git

Git: Fix a Worktree Blocking a Branch Delete It Doesn’t Need

- 27.11.26 - ErcanOPAK

🔀 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 list first 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 --force if 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 prune periodically 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 -rf instead of git worktree remove leaves 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.

— Version Control Tip

Related posts:

Git: Fix git rebase -i Reordering Commits Into a State That No Longer Compiles Because an Earlier Co...

Git: Fix git rebase -i Reordering Commits Into a State That No Longer Compiles Because an Earlier Co...

Git: Recover a Branch Deleted Before It Was Merged

Git: Recover a Branch Deleted Before It Was Merged

Git: Fix Large Files Checking Out as Tiny Text Pointers Because Git LFS Was Never Installed on That ...

Git: Fix Large Files Checking Out as Tiny Text Pointers Because Git LFS Was Never Installed on That ...

Views: 8
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

SQL Server: Fix a Temporal Table History Missing a Dropped Column
Git: Fix a Bisect Run Landing on an Unrelated Flaky Commit

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Read

  1. 01How to make theater mode the default for Youtube 1,079 views
  2. 02How to add default value for Entity Framework migrations for DateTime and Bool 996 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 995 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 873 views
  5. 05How to select distinct rows in a datatable in C# 866 views
  6. 06How to enable, disable and check if Service Broker is enabled on a database in SQL Server 671 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 629 views
  8. 08Average of all values in a column that are not zero in SQL 584 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 561 views
Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
Back to top
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com