Eric Sunshine <sunshine@xxxxxxxxxxxxxx> writes: > With git-checkout, it's very easy to accidentally get into a detached > HEAD state, so it makes some sense to protect newcomers, by default, > from that accident in git-switch. However, auto-creation of a new > local branch is not, for a couple reasons, nearly so weighty a matter. > First, in many cases it may be less likely to happen since it requires > presence of a corresponding remote tracking branch. Second, it's > intuitively easy to recover from it: when git-switch reports that it > created a new branch, though perhaps surprising, the user would > naturally know to look for a command to "delete a branch". > > And, unlike a detached HEAD, which newcomers may mistakenly believe > lead to irretrievable loss of work, an unexpected branch creation > carries no such penalty, perceived or real. I suspect that it actually cuts both ways. An auto-vivified local branch 'foo' that happens to have the same name as 'origin/foo' is still a different line of history UNLESS the user makes sure the divergence is reconciled with "push" and "pull" (possibly configured to "pull --rebase", but that is a secondary detail that depends on the workflow). Even when 'switch' reports that it created a new branch, a newcomer would probably not realize that it is "new", and different from the branch that the remote has. >> So if it is deemed to be too confusing to dwim in this >> case, could we add a hint suggesting the command? Something like: >> "No suitable branch <foo> found, however there is a remote tracking >> branch <origin/foo> that you can siwtch and create with `git switch >> --guess foo`" (or maybe the one without guess)? > > That could be helpful if git-switch continues to make --no-guess the > default, but making --guess the default (as it is in git-checkout) > would likely be even better (for the reasons enumerated above). I do not have a huge issue with making "--guess" the default, but then the user may be entitled to help with an advice message when the command, especially with the implicit "--guess", auto-vivifies a new local branch based on a remote-tracking branch to stress that this is a new branch and different from the history the remote side has.