How to check out a branch that is checked out on another worktree without switching to it #4622
-
Hi! Whenever I try to check out a branch that is active on another worktree, lazygit asks this:
If I press escape, the branch is not checked out. This means that having the branch checked out on another worktree prevents me from checking it out on my current one. This is not how I want to use worktrees, because it would force me to open the other worktree directory in my IDE. I just want to switch the branch and I don't care if it's checked out on another worktree. Is this possible with lazygit? If not, I think it should be changed. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
EDIT: upon taking a closer look, it's antithetical to your request. |
Beta Was this translation helpful? Give feedback.
-
I'm not very familiar with worktrees, I never use them, but as far as I understand, this is a limitation of git itself. You can't have the same branch checked out in two different worktrees. The only options you have is to switch to the other worktree, or cancel. If you do want to check it out in the current worktree, then you'd have to switch to that other worktree, check out some other branch there (or maybe a detached head), and then come back to the original one. You should then be able to check out the branch there. Are you suggesting that lazygit should do this for you? But doing it this way kind of defeats the purpose of worktrees, so I'm wondering why you use them at all then. |
Beta Was this translation helpful? Give feedback.
I'm not very familiar with worktrees, I never use them, but as far as I understand, this is a limitation of git itself. You can't have the same branch checked out in two different worktrees. The only options you have is to switch to the other worktree, or cancel.
If you do want to check it out in the current worktree, then you'd have to switch to that other worktree, check out some other branch there (or maybe a detached head), and then come back to the original one. You should then be able to check out the branch there. Are you suggesting that lazygit should do this for you?
But doing it this way kind of defeats the purpose of worktrees, so I'm wondering why you use them at all then.