Subject: Re: [PATCH 1/3] checkout: provide hint when failing due to another worktree

From: Phillip Wood <[email-masked]>
Date: Fri, 19 Sep 2025 15:13:23 +0100

Hi Gabriel

On 17/09/2025 16:25, Gabriel Scherer wrote:
> Dear git developers,
> 
> On 15/09/2025 21:52, Gabriel Scherer wrote:
>> (This gets me to wonder if a desirable behavior could be to 'detach' 
>> the other worktrees that had the same branch checked out, instead of 
>> failing on checkout. Users starting to use the other worktree again 
>> would possibly notice more quickly that something is amiss.)
> 
> After the new feedback from Junio, I wonder if I should explore this 
> suggestion more actively.
> 
> For now my goal has been to make --ignore-other-worktrees more 
> discoverable, for people who are willing to take the risk. (I am 
> comfortable doing this as I have used this workflow for years without 
> much trouble with the 'workdir' script, but clearly you want to be very 
> careful in how exactly we suggest that it is a possibility.)
> 
> Would you prefer a different option to detach the branch at the other 
> worktrees? This could be
>    git checkout --detach-other-worktrees <branch>
> for example.

In general we try to avoid having commands run in one worktree affect a 
checkout in another worktree so I'm not sure we'd really want to go that 
route.

> I did not originally consider this as it requires more expertise in git 
> internal data structures, but it may be easier than finding a way to 
> advertise --ignore-other-worktrees that you are really comfortable with.

I think it comes down to the same problem that we're not that 
comfortable with the idea of having the same branch checked out in 
multiple worktrees. I'd have though having some advice that suggests 
using --detach should be relatively uncontroversial. Suggesting 
"--ignore-other-worktrees" would certainly require some kind of warning. 
If it is hard to come up with a concise hint maybe we could have an 
expanded discussion in the documentation and have the hint refer to that?

Thanks

Phillip