]> git.ipfire.org Git - thirdparty/git.git/commit
branch: suggest <remote>/<branch> on upstream slip
authorHarald Nordgren <haraldnordgren@gmail.com>
Sat, 27 Jun 2026 18:02:24 +0000 (18:02 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sun, 28 Jun 2026 02:36:43 +0000 (19:36 -0700)
commit2faf0f0256cbf4cef447202276ca57d36e1d9380
tree420e6cf1db9289ba7ae23146b10725a503848d93
parent4621f8ce5e9b97aa2e8d0d9ffe9d25df2471074d
branch: suggest <remote>/<branch> on upstream slip

When setting the upstream of the current branch to the 'main' branch
of the remote 'origin', i.e.,

    $ git branch --set-upstream-to origin/main

it is easy to mistakenly write

    $ git branch --set-upstream-to origin main

That is parsed as a request to set the upstream of the local branch
'main' to 'origin'. When 'main' does not exist, the command dies
with:

    fatal: branch 'main' does not exist

pointing at a branch the user never meant to name. When 'main' does
exist, it instead dies with:

    fatal: the requested upstream branch 'origin' does not exist

leaving the user equally puzzled.

When the operated-on branch is missing and '<remote>/<branch>' names
a real remote-tracking ref, suggest the intended form:

    $ git branch --set-upstream-to=origin/main

The suggestion is gated on '<remote>/<branch>' existing so it only
appears when a slipped slash is the likely explanation.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/branch.c
t/t3200-branch.sh