Re: [PATCH 1/2] branch: suggest <remote>/<branch> on upstream slip
Show 31 quoted lines
> Le 22 juin 2026 à 15:58, Junio C Hamano <gitster@pobox.com> a écrit :
>
> "Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
>> 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
Relatedly, if memory serves: when origin/HEAD is available locally, this works to set sample’s upstream branch to whatever origin/HEAD refers to, right? So it may not even be a mistake. (I’m pretty sure I’ve used something like « git branch -u origin » when I didn’t give an upstream of « origin » to « git switch -c branch » for various reasons.)