Re: [PATCH 1/2] branch: suggest <remote>/<branch> on upstream slip
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 22, 2026, 19:56 UTC
- Message-ID
- <xmqq1pdytkmj.fsf@gitster.g>
- In-Reply-To
- <21684539debaf433b6b63404e1a7622a5cc33283.1781262619.git.gitgitgadget@gmail.com>
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 5 quoted lines
> From: Harald Nordgren <haraldnordgren@gmail.com> > > "git branch --set-upstream-to origin main" reads the trailing word as > the local branch to operate on and dies with "branch 'main' does not > exist", pointing at the wrong problem.
When 'main' does not exist locally,
$ git branch --set-upstream-to "$anything" main
would fail before even looking at the "$anything" (which is supposed to specify the new_upstream for the named local branch 'main'). The operation is to set the upstream for 'main', and if 'main' does not exist, doesn't the user deserve the error that says 'main' does not exist, no matter what "$anything" is, whether it is a well-formed or ill-formed remote tracking branch name?
So it is unclear, at least to me, why "branch 'main' does not exist" is an inappropriate message, mostly because these three lines does not clearly tell me what the user _expected_ the command line to do.
When 'main' does exist, but named upstream "$anything" does not, we get
$ git branch sample master ;# make sure the thing exists
$ git branch --set-upstream-to origin sample
fatal: the requested upstream branch 'origin' does not exist
hint:
hint: If you are planning on basing your work on an upstream
hint: branch that already exists at the remote, you may need to
hint: run "git fetch" to retrieve it.
hint:
hint: If you are planning to push out a new local branch that
hint: will track its remote counterpart, you may want to use
hint: "git push -u" to set the upstream config as you push.
hint: Disable this message with "git config set advice.setUpstreamFailure false"which does sound clear enough to me, even though it does not exactly say "Even though upstream branch 'origin' does not exist, 'origin' is a nickname for a remote, perhaps you meant to say origin/something?"
I do not doubt you are trying to address a real issue, but the above three-line description does not tell me what that problem is.
Now I do not regularly use --set-upstream-to, so I may be missing an obvious common mistake modes, but a couple of my attempts to make bad command invocations seem to give me reasonable responses:
$ git branch --set-upstream-to ko/master sample
branch 'sample' set up to track 'ko/master'.OK, both are well formed so no problem.
$ git branch --set-upstream-to ko/mastre sample
fatal: the requested upstream branch 'ko/mastre' does not exist
hint:
hint: If you are planning on basing your work on an upstream
hint: branch that already exists at the remote, you may need to
hint: run "git fetch" to retrieve it.
hint:
hint: If you are planning to push out a new local branch that
hint: will track its remote counterpart, you may want to use
hint: "git push -u" to set the upstream config as you push.
hint: Disable this message with "git config set advice.setUpstreamFailure false"Misspelt upstream branch name diagnosed correctly, just like the case where I gave 'origin', which does not exist, either.