tl;dr: Checking out a branch which is already checked out in another worktree is illegal.
Enter git checkout --detach master
Now to more clearly explain how one gets to such situation, the following is a real world example of how I personally use git checkout --detach
.
I am developing a program, called midimap, that I also have a stable long lived process of running in the background.
For that I utilize two worktrees, ~/vc/github.com/fossegrim/midimap
, hereby referred to as DEV, for development and ~/vc/github.com/fossegrim/midimap-stable
, hereby referred to as STABLE, for the long lived process.
When I start my computer I run the midimap program in STABLE and open GNU Emacs in DEV. As I work on my project in DEV I will eventually come to a point where I want to update the USAGE worktree to contain the changes of DEV.
Since checking out a branch which is already checked out in another worktree is illegal. I have to check it out another way: git checkout --detach master
.