Add "Detach worktree" option when checking out a branch occupied by another worktree#5341
Add "Detach worktree" option when checking out a branch occupied by another worktree#5341ruudk wants to merge 1 commit intojesseduffield:masterfrom
Conversation
…nother worktree When working with worktrees it's common to have a main project installation (e.g. running your database and services) alongside several worktrees for feature work. Previously, checking out a branch occupied by another worktree only offered "Switch to worktree", forcing you to switch to that worktree, detach it, then navigate back and check out the branch — a tedious round-trip. Now the prompt shows a menu with two options: "Switch to worktree" and "Detach worktree". The detach option runs `git checkout --detach` on the other worktree and then checks out the branch in one step. The detach option is disabled when the other worktree has uncommitted changes, to prevent accidental loss of work.
|
Makes some sense, but I'm curious why you want this, rather than just switch to the worktree that has the branch already checked out. One reason that I could imagine: when I watch people use git (or lazygit), and they want to create a new branch from main, I often see them check out main first, pull it, and then create a new branch from it. So if main is checked out in a worktree, this would explain why you want your new feature. Note that this is unnecessary though: to create a new branch from main, simply select it in the branches list and press Any other reasons? |
|
I have my application and services booted in my main repository. The worktrees don't have that because it would eat resources. Occasionally I want to bring some of these features to my main repository and run it functionally. Does that make sense? |
|
Yes, thanks. I'm out of time today, so this PR probably won't make it for the release tomorrow; hope that's ok. |
|
Sure, no rush! Thanks for taking the time to review it |
PR Description
Please check if the PR fulfills these requirements
go generate ./...)When working with worktrees it's common to have a main project installation (e.g. running your database and services) alongside several worktrees for feature work. Previously, checking out a branch occupied by another worktree only offered "Switch to worktree", forcing you to switch to that worktree, detach it, then navigate back and check out the branch: a tedious round-trip.
This is the current behavior:

Now the prompt shows a menu with two options: "Switch to worktree" and "Detach worktree". The detach option runs


git checkout --detachon the other worktree and then checks out the branch in one step.The detach option is disabled when the other worktree has uncommitted changes, to prevent accidental loss of work.
