git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] branch: suggest <remote>/<branch> on upstream slip

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 22, 2026, 21:35 UTC
Message-ID
<xmqqh5mus1ga.fsf@gitster.g>
In-Reply-To
<xmqq1pdytkmj.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 22 quoted lines
> "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.

After pondering on this a bit, I _think_ (but I am guessing, and your job as an author of proposed commit log message is to make sure your readers do not have to guess) what the user expected was to set the upstream for the currrent branch.

    When trying to set the upstream for the current branch to "main"
    branch of the remote "origin", i.e.,
        $ git branch --set-upstream-to origin/main
    it is easy for some users to mistakenly say
        $ git branch --set-upstream-to origin main
    But it is a request to set the upstream for the local branch
    "main" to "origin", which is not expected to work as the
    upstream most likely would look like <remote>/<branch> (e.g.,
    "origin/main").  The user would get either one of these errors:
        fatal: branch 'main' does not exist
        fatal: the requested upstream branch 'origin' does not exist
    Give a hint that we _suspect_ the user may have meant to set the
    upstream of the current branch to 'origin/main' (but do so only
    when 'origin/main' does exist), and tell them the right way to
    spell that request.
or something perhaps?
Previous: Junio C HamanoNext: Ben Knoble
Message 4 of 26 in “branch/push: suggest intended form when remote/branch slip given”
  1. 0/2 branch/push: suggest intended form when remote/branch slip givenHarald Nordgren via GitGitGadget, Jun 12, 2026
  2. 1/2 branch: suggest <remote>/<branch> on upstream slipHarald Nordgren via GitGitGadget, Jun 12, 2026
  3. Junio C HamanoJun 22, 2026
  4. Junio C HamanoJun 22, 2026
  5. Ben KnobleJun 24, 2026
  6. 2/2 push: suggest <remote> <branch> for a slash slipHarald Nordgren via GitGitGadget, Jun 12, 2026
  7. Junio C HamanoJun 22, 2026
  8. Harald NordgrenJun 22, 2026
  9. Weijie YuanJun 22, 2026
  10. Junio C HamanoJun 22, 2026
  11. Harald NordgrenJun 23, 2026
  12. 0/2 branch/push: suggest intended form when remote/branch slip givenHarald Nordgren via GitGitGadget, Jun 24, 2026
  13. 1/2 branch: suggest <remote>/<branch> on upstream slipHarald Nordgren via GitGitGadget, Jun 24, 2026
  14. Junio C HamanoJun 24, 2026
  15. Harald NordgrenJun 25, 2026
  16. Junio C HamanoJun 25, 2026
  17. 2/2 push: suggest <remote> <branch> for a slash slipHarald Nordgren via GitGitGadget, Jun 24, 2026
  18. Junio C HamanoJun 24, 2026
  19. Junio C HamanoJun 25, 2026
  20. Harald NordgrenJun 25, 2026
  21. Junio C HamanoJun 25, 2026
  22. 0/2 branch/push: suggest intended form when remote/branch slip givenHarald Nordgren via GitGitGadget, Jun 27, 2026
  23. 1/2 branch: suggest <remote>/<branch> on upstream slipHarald Nordgren via GitGitGadget, Jun 27, 2026
  24. Junio C HamanoJun 28, 2026
  25. Harald NordgrenJun 28, 2026
  26. 2/2 push: suggest <remote> <branch> for a slash slipHarald Nordgren via GitGitGadget, Jun 27, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.