This will help users who just want to check an existing branch out into a new worktree, and save a few keystrokes.Īs the current behaviour is to simply ' die()' when a branch with the name However we can do a little better than that, and check the branch out if If a branch with that name already exists, the command refuses to do anything, unless the ' -force' option is given. (Merged by Junio C Hamano - gitster - in commit 10174da, ) worktree: teach " add" to check out existing branchesĬurrently ' git worktree add ' creates a new branch named after the See commit f60a7b7, commit 6427f87, commit 2c27002, commit d861d34 () by Thomas Gummerer ( tgummerer). " git worktree add" learned to check out an existing branch.
In addition of "guessing the remote branch", as I explain in my other answer, Git 2.18 (Q2 2018) will offer a new feature: zorg, which is of course just zorg, so this tries to check out the existing branch zorg into the new work-tree. Here, since there is neither a -b zorg nor a final argument, Git figures out the branch name by using the last part of. zorg, you can just run: git worktree add.
Rather than trying to figure out how to deal with these-by either educating programmers or providing tools to deal with the problems- git worktree simply forbids the situation entirely. Having two different work-trees with independent index objects but the same underlying branch leads to some tricky problems for users to deal with. This is because, while each added work-tree has its own index and HEAD, the HEAD files wind up sharing the underlying branch pointers in the shared repository. north northįirst, a reminder (or information for others coming across this question): git worktree add wants to create a new work-tree and, at the same time, make sure that this new work-tree is using a different branch name from every other work-tree. TL DR: you probably wanted git worktree add.