3 ms·
Worktrees are pretty great but I don't understand why I can't have the same branch checked out on two worktrees? I get why committing to a branch checked out el
by uses 3y ago
Worktrees are pretty great but I don't understand why I can't have the same branch checked out on two worktrees? I get why committing to a branch checked out elsewhere might be bad, but in that case, just prevent me from committing, like "you can't commit because the branch is checked out elsewhere - maybe create a new branch".
- renewiltord 3y agoIn general, `git` seems to fight changing checked out code. You can't push refs to a repo on a checked out branch, for example.
- CuriousCosmic 3y agoYou can absolutely check it out in multiple places. You get a warning because the behavior is unintuitive. If you want to force it to do it anyways you just use -f/--force. When you check out a branch, the expectation is that the working tree is in sync with the current head commit. If you check out the same branch in multiple places, then if you commit on worktree a, worktree b won't say that it's still on the old commit, it'll just say that the diff between the current head and the contents of worktree b's working directory are a bunch of uncommitted changes. That's why it's unintuitive. This is clearly not the intended behavior for most users when they want to check out the same branch in multiple places. They want to check out a given commit that happens to be the head of the current branch in multiple places. To do that you use --detach so that the worktree head points to the commit rather than the branch itself.