Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

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

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
Git

Git: Fix a Worktree That Refuses to Check Out a Branch Already Checked Out Elsewhere

- 26.09.26 - ErcanOPAK

🔀 The Branch You Need Is ‘Already in Use’ Somewhere Else

Git worktrees let you have several working directories from a single repository, checked out to different branches at the same time – but Git refuses to check out the SAME branch into two worktrees at once, and the error message doesn’t always make clear which other worktree is holding onto it.

🔎 The Problem

$ git worktree add ../hotfix-review feature/checkout-flow
fatal: '"'"'feature/checkout-flow'"'"' is already checked out at
'"'"'/home/dev/project-worktrees/feature-work'"'"'

# Git treats a branch as a single checkout target across the whole
# repository - it can be the current branch in only one worktree (or
# the main working directory) at a time, by design, to prevent two
# working directories from independently modifying the same branch
# and silently clobbering each other'"'"'s changes.

✅ Fix: Find the Other Worktree, or Use a Detached Checkout

  • `git worktree list` shows every worktree and which branch each one currently has checked out – the fastest way to find exactly where the branch is already in use before deciding what to do about it.
  • If the other worktree isn’t actively being used, `git worktree remove <path>` frees the branch up, or simply switching that worktree to a different branch (`git -C <path> switch main`) releases the lock without deleting anything.
  • For read-only inspection – reviewing a branch without needing to commit to it – `git worktree add –detach ../hotfix-review feature/checkout-flow` checks out that commit in a detached HEAD state, which Git allows in multiple worktrees simultaneously since there’s no branch pointer being shared.

⚠️ Why This Trips Up Teams New to Worktrees

  • The restriction applies to the branch, not the commit – two worktrees can absolutely be at the exact same commit as long as neither one has that commit’s branch checked out by name, which is a subtle enough distinction to cause confusion the first few times.
  • A worktree left behind after its directory was deleted manually (instead of through `git worktree remove`) still shows up in `git worktree list` as holding its branch – `git worktree prune` clears out these stale, no-longer-existing entries.

A branch can live in more than one place on disk, but Git only ever lets one of them actually claim to be it.

— Version Control Tip

Related posts:

Git: Fix a .gitattributes Change That Doesn't Apply to Files Already Committed

Git: Fix a .gitattributes Change That Doesn't Apply to Files Already Committed

Git: Advanced Branching Strategies for Teams

Git: Advanced Branching Strategies for Teams

Git: Fix Line Ending Warnings That Mark Every File as Changed After a Fresh Clone

Git: Fix Line Ending Warnings That Mark Every File as Changed After a Fresh Clone

Views: 23

Post navigation

The AI Prompt That Turns a Confusing Product Warranty Into a Plain-English Answer to ‘Am I Covered?’
SQL Server: Fix a Login That Works Fine in SSMS but Fails Every Time From the Application

Leave a Reply Cancel reply

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

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,068)
  • Get the User Name and Domain Name from an Email Address in SQL (990)
  • How to add default value for Entity Framework migrations for DateTime and Bool (986)
  • Get the First and Last Word from a String or Sentence in SQL (865)
  • How to select distinct rows in a datatable in C# (859)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (661)
  • Add Constraint to SQL Table to ensure email contains @ (619)
  • Average of all values in a column that are not zero in SQL (577)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (553)
  • Find numbers with more than two decimal places in SQL (481)

Recent Posts

  • Network Speed Monitor Windows Application v2.5.1
  • Ağ Hızı İzleyici Windows Uygulaması v2.5.1
  • How to make theater mode the default for Youtube
  • The AI Prompt That Audits a Function for Thread-Safety Gaps
  • Ajax: Fix a Fetch Request Caching a Response Despite No-Store
  • WordPress: Fix a Navigation Block Losing Submenu Items After Sync
  • Visual Studio: Fix CodeLens Reference Counts Stuck at Stale Numbers
  • C#: Fix a UTF-8 String Literal Behaving Differently in a Switch
  • Photoshop: Fix a Liquify Mesh Snapping Back on a Smart Object
  • The AI Prompt That Turns a Crash Dump Into a Short Repro Script

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,068)
  • Get the User Name and Domain Name from an Email Address in SQL (990)
  • How to add default value for Entity Framework migrations for DateTime and Bool (986)
  • Get the First and Last Word from a String or Sentence in SQL (865)
  • How to select distinct rows in a datatable in C# (859)

Recent Posts

  • Network Speed Monitor Windows Application v2.5.1
  • Ağ Hızı İzleyici Windows Uygulaması v2.5.1
  • How to make theater mode the default for Youtube
  • The AI Prompt That Audits a Function for Thread-Safety Gaps
  • Ajax: Fix a Fetch Request Caching a Response Despite No-Store

Social

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