3 ms·
Does worktree allow checking out the same branch but at different commits?
by lloydatkinson 3y ago
Does worktree allow checking out the same branch but at different commits?
- matrss 3y agoNo, because a branch is a (re-assignable) name for some commit and cannot point at different commits while in the same repository at the same time. A "branch but at different commits" simply makes no sense. You can however create a worktree with a detached HEAD pointing at any commit. By default it seems to create a branch for each worktree.
- SpaceNugget 3y agoSomewhat pedantic but relevant. A branch is a single commit. There aren't different commits _in_ a branch to checkout. Regardless, if you are asking whether you can check out commit that doesn't have a branch pointing at it, yes you can. You can have a work tree for every commit in your repository if you like.
- glandium 3y agoYou can have multiple work trees for the same commit, for that matter, as long as they are the same branch (so with different branches pointing at the same commit, or detached heads)
- gpderetta 3y agoto be even more pedantic, a branch is a (named) pointer to a commit. You can have multiple names pointing to that commit.