{"thread":{"id":"66591","subject":"[PATCH] status: reword message for a missing upstream branch","startedAt":"2026-10-19T17:57:22Z","lastAt":"2026-11-19T18:05:37Z","messageCount":14,"participants":["Elia Pinto","Harald Nordgren","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"555443","messageId":"20261019175722.5223-1-gitter.spiros@gmail.com","threadId":"66591","inReplyTo":null,"subject":"[PATCH] status: reword message for a missing upstream branch","fromName":"Elia Pinto","fromEmail":"gitter.spiros@gmail.com","sentAt":"2026-10-19T17:57:22Z","receivedAt":"2026-10-19T17:57:22Z","isPatch":true,"sender":{"key":"gitter.spiros@gmail.com","avatar":"https://avatars.githubusercontent.com/u/158490?v=4"},"body":"Clone an empty repository, make a commit and run \"git status\":\n\n    $ git init --bare empty.git\n    $ git clone empty.git work && cd work\n    $ git commit --allow-empty -m initial\n    $ git status\n    On branch master\n    Your branch is based on 'origin/master', but the upstream is gone.\n      (use \"git branch --unset-upstream\" to fixup)\n\nThe upstream is not gone, it was never there: the remote is empty,\nso origin/master has not been created yet. The advice is also not\nwhat the user needs; \"git push\" creates origin/master and the\nmessage goes away.\n\nThe message was added in f2e087395b (branch: report invalid tracking\nbranch as gone, 2013-08-26), assuming that a configured upstream that\ncannot be resolved must have been deleted. But \"git clone\" of an empty\nrepository configures the upstream anyway, and Git has no way to tell\n\"deleted\" from \"not created yet\".\n\nSince we cannot tell the two cases apart, change the message for both,\nincluding the \"deleted\" case that has been reported as \"gone\" since\n2013, so that it is correct either way:\n\n    Your branch is set up to track 'origin/master', which does not exist.\n      (use \"git push\" to create it)\n      (use \"git branch --unset-upstream\" to stop tracking it)\n\nOnly suggest \"git push\" when it would actually create the upstream,\nthat is when the push destination of the branch (what \"@{push}\"\nresolves to) is the upstream itself. This is not the case, for\nexample, with push.default set to \"nothing\", or when pushing to a\ndifferent remote (branch.<name>.pushRemote or remote.pushDefault).\nIt is also not the case with push.default set to \"matching\": it only\npushes branches that already exist on the remote, so it would not\ncreate the missing upstream. In all these cases only suggest\n\"git branch --unset-upstream\".\n\n\"git checkout\" prints the same message, so it changes too. The\n\"[gone]\" shown by \"git status -sb\", \"git branch -vv\" and\n\"%(upstream:track)\" is not changed, as scripts may depend on it.\n\nSigned-off-by: Elia Pinto <gitter.spiros@gmail.com>\n---\nThis is an RFC mainly about the wording. The case of a freshly cloned\nempty repository has been confusing users for a while, e.g.\nhttps://stackoverflow.com/questions/24870145\n\nI could not find a previous discussion of this case on the list.\nOpinions on whether \"status:\" or \"remote:\" is the better area prefix\nare also welcome, as \"git checkout\" shows the same message.\n\nThis is a resubmission of this patch, which I haven't seen in \n'seen' or 'next' https://lore.kernel.org/git/20261009134004.188952-1-gitter.spiros@gmail.com/\nThanks \n\n remote.c                 |  34 +++++++++--\n t/t6040-tracking-info.sh | 120 ++++++++++++++++++++++++++++++++++++++-\n 2 files changed, 146 insertions(+), 8 deletions(-)\n\ndiff --git a/remote.c b/remote.c\nindex 71170f36a9..4ed4d1ee2f 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -2442,6 +2442,31 @@ static void format_branch_comparison(struct strbuf *sb,\n \t}\n }\n \n+/*\n+ * Would a plain \"git push\" create the remote-tracking ref \"upstream\"?\n+ * Not with \"matching\", which only updates branches that already exist\n+ * on the remote.\n+ */\n+static bool push_creates(const char *push_ref, const char *upstream)\n+{\n+\treturn push_ref && !strcmp(push_ref, upstream) &&\n+\t       repo_config_values(the_repository)->push_default !=\n+\t       PUSH_DEFAULT_MATCHING;\n+}\n+\n+static void format_missing_upstream(struct strbuf *sb, const char *name,\n+\t\t\t\t    bool suggest_push)\n+{\n+\tstrbuf_addf(sb, _(\"Your branch is set up to track '%s', \"\n+\t\t\t  \"which does not exist.\\n\"), name);\n+\tif (!advice_enabled(ADVICE_STATUS_HINTS))\n+\t\treturn;\n+\tif (suggest_push)\n+\t\tstrbuf_addstr(sb, _(\"  (use \\\"git push\\\" to create it)\\n\"));\n+\tstrbuf_addstr(sb, _(\"  (use \\\"git branch --unset-upstream\\\" \"\n+\t\t\t    \"to stop tracking it)\\n\"));\n+}\n+\n /*\n  * Return true when there is anything to report, otherwise false.\n  */\n@@ -2503,12 +2528,9 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,\n \n \t\tif (cmp < 0) {\n \t\t\tif (is_upstream) {\n-\t\t\t\tstrbuf_addf(sb,\n-\t\t\t\t\t_(\"Your branch is based on '%s', but the upstream is gone.\\n\"),\n-\t\t\t\t\tshort_ref);\n-\t\t\t\tif (advice_enabled(ADVICE_STATUS_HINTS))\n-\t\t\t\t\tstrbuf_addstr(sb,\n-\t\t\t\t\t\t_(\"  (use \\\"git branch --unset-upstream\\\" to fixup)\\n\"));\n+\t\t\t\tformat_missing_upstream(sb, short_ref,\n+\t\t\t\t\t\t\tpush_creates(push_ref,\n+\t\t\t\t\t\t\t\t     full_ref));\n \t\t\t\treported = 1;\n \t\t\t}\n \t\t\tfree(full_ref);\ndiff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh\nindex e95d420972..39cb755ccc 100755\n--- a/t/t6040-tracking-info.sh\n+++ b/t/t6040-tracking-info.sh\n@@ -96,7 +96,7 @@ test_expect_success 'checkout (upstream is gone)' '\n \t\tcd test &&\n \t\tgit checkout b5\n \t) >actual &&\n-\ttest_grep \"is based on .*, but the upstream is gone.\" actual\n+\ttest_grep \"set up to track .*, which does not exist.\" actual\n '\n \n test_expect_success 'checkout (up-to-date with upstream)' '\n@@ -123,7 +123,123 @@ test_expect_success 'status (upstream is gone)' '\n \t\t# reports nothing to commit\n \t\ttest_must_fail git commit --dry-run\n \t) >actual &&\n-\ttest_grep \"is based on .*, but the upstream is gone.\" actual\n+\ttest_grep \"set up to track .*, which does not exist.\" actual\n+'\n+\n+test_expect_success 'setup clone of an empty repository' '\n+\tgit init --bare empty.git &&\n+\tgit clone empty.git empty-clone &&\n+\tgit -C empty-clone commit --allow-empty -m initial\n+'\n+\n+test_expect_success 'status (upstream not yet pushed after empty clone)' '\n+\tcat >expect <<-EOF &&\n+\tOn branch main\n+\tYour branch is set up to track ${SQ}origin/main${SQ}, which does not exist.\n+\t  (use \"git push\" to create it)\n+\t  (use \"git branch --unset-upstream\" to stop tracking it)\n+\n+\tnothing to commit, working tree clean\n+\tEOF\n+\tgit -C empty-clone status >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'checkout (upstream not yet pushed after empty clone)' '\n+\ttest_when_finished \"git -C empty-clone branch -D tmp\" &&\n+\tcat >expect <<-EOF &&\n+\tYour branch is set up to track ${SQ}origin/main${SQ}, which does not exist.\n+\t  (use \"git push\" to create it)\n+\t  (use \"git branch --unset-upstream\" to stop tracking it)\n+\tEOF\n+\tgit -C empty-clone checkout -b tmp &&\n+\tgit -C empty-clone checkout main >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'status -s -b (upstream not yet pushed after empty clone)' '\n+\techo \"## main...origin/main [gone]\" >expect &&\n+\tgit -C empty-clone status -s -b >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'setup expected output without \"git push\" advice' '\n+\tcat >expect-no-push <<-EOF\n+\tOn branch main\n+\tYour branch is set up to track ${SQ}origin/main${SQ}, which does not exist.\n+\t  (use \"git branch --unset-upstream\" to stop tracking it)\n+\n+\tnothing to commit, working tree clean\n+\tEOF\n+'\n+\n+test_expect_success 'status (missing upstream, push.default=nothing)' '\n+\tgit -C empty-clone -c push.default=nothing status >actual &&\n+\ttest_cmp expect-no-push actual\n+'\n+\n+# \"matching\" only updates branches that already exist on the remote\n+test_expect_success 'status (missing upstream, push.default=matching)' '\n+\tgit -C empty-clone -c push.default=matching status >actual &&\n+\ttest_cmp expect-no-push actual\n+'\n+\n+test_expect_success 'status (missing upstream, pushRemote is another remote)' '\n+\tgit init --bare fork.git &&\n+\tgit -C empty-clone remote add fork ../fork.git &&\n+\tgit -C empty-clone -c branch.main.pushRemote=fork status >actual &&\n+\ttest_cmp expect-no-push actual\n+'\n+\n+test_expect_success 'status (missing upstream, advice.statusHints=false)' '\n+\tcat >expect <<-EOF &&\n+\tOn branch main\n+\tYour branch is set up to track ${SQ}origin/main${SQ}, which does not exist.\n+\n+\tnothing to commit, working tree clean\n+\tEOF\n+\tgit -C empty-clone -c advice.statusHints=false status >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'setup upstream deleted on the remote and pruned' '\n+\tgit init --bare pruned.git &&\n+\tgit clone pruned.git pruned-clone &&\n+\t(\n+\t\tcd pruned-clone &&\n+\t\tgit commit --allow-empty -m initial &&\n+\t\tgit push origin main &&\n+\t\tgit checkout -b topic &&\n+\t\tgit push -u origin topic\n+\t) &&\n+\tgit -C pruned.git branch -D topic &&\n+\tgit -C pruned-clone fetch --prune\n+'\n+\n+test_expect_success 'status (upstream deleted on the remote and pruned)' '\n+\tcat >expect <<-EOF &&\n+\tOn branch topic\n+\tYour branch is set up to track ${SQ}origin/topic${SQ}, which does not exist.\n+\t  (use \"git push\" to create it)\n+\t  (use \"git branch --unset-upstream\" to stop tracking it)\n+\n+\tnothing to commit, working tree clean\n+\tEOF\n+\tgit -C pruned-clone status >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'short formats still show \"gone\" for a deleted upstream' '\n+\techo \"## topic...origin/topic [gone]\" >expect &&\n+\tgit -C pruned-clone status -s -b >actual &&\n+\ttest_cmp expect actual &&\n+\tgit -C pruned-clone branch -vv >actual &&\n+\ttest_grep \"^\\* topic .* \\[origin/topic: gone\\] initial$\" actual &&\n+\techo \"topic [gone]\" >expect &&\n+\tgit -C pruned-clone for-each-ref \\\n+\t\t--format=\"%(refname:short) %(upstream:track)\" \\\n+\t\trefs/heads/topic >actual &&\n+\ttest_cmp expect actual\n '\n \n test_expect_success 'status (up-to-date with upstream)' '\n-- \n2.53.0\n\n\n"},{"id":"555445","messageId":"CAHwyqnW4TjE_g9dEqAYdVdgM1dg3246hzsCVwsUBLzzLz5_U_w@mail.gmail.com","threadId":"66591","inReplyTo":"20261019175722.5223-1-gitter.spiros@gmail.com","subject":"Re: [PATCH] status: reword message for a missing upstream branch","fromName":"Harald Nordgren","fromEmail":"haraldnordgren@gmail.com","sentAt":"2026-10-19T18:04:56Z","receivedAt":"2026-10-19T18:04:56Z","isPatch":true,"sender":{"key":"haraldnordgren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9569897?v=4"},"body":"Hi Elia!\n\nIs this a duplicate, seems you sent out the same thing here already?\nhttps://lore.kernel.org/git/20261009134004.188952-1-gitter.spiros@gmail.com/\n\n\nHarald\n\n"},{"id":"555474","messageId":"xmqqzew91i5g.fsf@gitster.g","threadId":"66591","inReplyTo":"20261019175722.5223-1-gitter.spiros@gmail.com","subject":"Re: [PATCH] status: reword message for a missing upstream branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-19T21:42:51Z","receivedAt":"2026-10-19T21:42:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Elia Pinto <gitter.spiros@gmail.com> writes:\n\n> The message was added in f2e087395b (branch: report invalid tracking\n> branch as gone, 2013-08-26), assuming that a configured upstream that\n> cannot be resolved must have been deleted. But \"git clone\" of an empty\n> repository configures the upstream anyway, and Git has no way to tell\n> \"deleted\" from \"not created yet\".\n\nI am totally with you up to this point.  This is a great issue to\ntackle.  I am curious to learn how you would solve it without\nthrowing the baby with bathwater, though.  Let me read on.\n\n> Since we cannot tell the two cases apart, change the message for both,\n> including the \"deleted\" case that has been reported as \"gone\" since\n> 2013, so that it is correct either way:\n>\n>     Your branch is set up to track 'origin/master', which does not exist.\n>       (use \"git push\" to create it)\n>       (use \"git branch --unset-upstream\" to stop tracking it)\n\nAhh, \"does not exist\".  Clever.  That does cover both cases and\nreads reasonably natural.  If we wanted to have something short that\nwe can reuse elsewhere (like inside [] in place of [gone]), we could\nsay which is \"missing\", perhaps.\n\nDo we emit \"git push\" suggestion unconditionally (meaning, does \"git\npush\" immediately in this state always create the \"upstream\" that\ndoes not exist yet), or do we have to check if \"git push\" will\ncreate it before saying so?\n\n> Only suggest \"git push\" when it would actually create the upstream,\n> that is when the push destination of the branch (what \"@{push}\"\n> resolves to) is the upstream itself.\n\nAh, your flow of explanation exactly matches how I explore the\npossibilities in my head, given the thinking of the author revealed\nso far.  Excellent log message that is very easy to follow.\n\n> This is not the case, for\n> example, with push.default set to \"nothing\", or when pushing to a\n> different remote (branch.<name>.pushRemote or remote.pushDefault).\n> It is also not the case with push.default set to \"matching\": it only\n> pushes branches that already exist on the remote, so it would not\n> create the missing upstream. In all these cases only suggest\n> \"git branch --unset-upstream\".\n\nIndeed.  That sounds like a good way to go.\n\n> \"git checkout\" prints the same message, so it changes too. The\n> \"[gone]\" shown by \"git status -sb\", \"git branch -vv\" and\n> \"%(upstream:track)\" is not changed, as scripts may depend on it.\n\nDoes this refer to what wt_shortstatus_print_tracking() says?  It is\n_(translated), so in a sense it is a fair game to be improved.\n\n\n"},{"id":"555504","messageId":"20261020072924.42026-1-gitter.spiros@gmail.com","threadId":"66591","inReplyTo":"xmqqzew91i5g.fsf@gitster.g","subject":"Re: [PATCH] status: reword message for a missing upstream branch","fromName":"Elia Pinto","fromEmail":"gitter.spiros@gmail.com","sentAt":"2026-10-20T07:29:24Z","receivedAt":"2026-10-20T07:29:24Z","isPatch":true,"sender":{"key":"gitter.spiros@gmail.com","avatar":"https://avatars.githubusercontent.com/u/158490?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Ahh, \"does not exist\".  Clever.  That does cover both cases and\n> reads reasonably natural.  If we wanted to have something short that\n> we can reuse elsewhere (like inside [] in place of [gone]), we could\n> say which is \"missing\", perhaps.\n\n\"missing\" sounds good to me for the short form. I'd rather keep it\nout of this patch, though; see below for why the bracketed label\nneeds a bit more care than the long message.\n\n> Do we emit \"git push\" suggestion unconditionally (meaning, does \"git\n> push\" immediately in this state always create the \"upstream\" that\n> does not exist yet), or do we have to check if \"git push\" will\n> create it before saying so?\n\nWe check, as the next paragraph of the log says: the hint is given\nonly when @{push} resolves to the upstream itself, and push.default\nis not \"matching\".\n\nThe check errs on the side of not giving the hint. For example, with\npush.default=matching but an explicit remote.<name>.push refspec,\n\"git push\" uses the refspec and would create the upstream, but we\nstill do not suggest it, because push_creates() looks at push.default\nwithout checking whether a refspec overrides it. I'll fix that in v2\nby checking push.default only when the remote has no push refspec\nand is not a mirror, which is the same order branch_get_push_1()\nfollows.\n\n> Does this refer to what wt_shortstatus_print_tracking() says?  It is\n> _(translated), so in a sense it is a fair game to be improved.\n\nYes, and you are right, the justification in the log message is\nwrong for some of the commands it lists. Looking more closely:\n\n - \"git status -sb\" uses LABEL(N_(\"gone\")) in\n   wt_shortstatus_print_tracking(), so it is translated (e.g.\n   \"[sparito]\" in Italian).\n\n - \"git status --porcelain -b\" goes through the same function, but\n   wt_porcelain_print() sets s->no_gettext, so it always says\n   \"[gone]\". That one has to stay.\n\n - \"git status --porcelain=v2\" never says \"gone\"; it prints\n   \"# branch.upstream\" and omits the \"# branch.ab\" line.\n\n - \"%(upstream:track)\" in \"git for-each-ref\" uses the untranslated\n   \"gone\" from ref-filter.c, which is documented in\n   git-for-each-ref.adoc, so that one has to stay too. But \"git\n   branch\" (and \"git tag\") call setup_ref_filter_porcelain_msg(),\n   so \"git branch -vv\" and \"git branch --format=%(upstream:track)\"\n   show the translated label.\n\nSo \"scripts may depend on it\" is true only for --porcelain and\nfor-each-ref. The other two are human-readable output and could be\nchanged.\n\nI am still hesitant to change the label in \"git branch -vv\" as part\nof this patch. Translated or not, under LC_ALL=C it says \"gone\", and\n\n    git branch -vv | grep ': gone]'\n\nis a very common recipe for finding branches whose upstream was\npruned. To keep the porcelain output as \"gone\" while changing the\nhuman output, wt_shortstatus_print_tracking() also could not keep\nusing LABEL() with a single msgid.\n\nSo for v2 I plan to leave the bracketed label alone and correct the\nlog message to say what is really going on. If we want \"[missing]\"\nin \"git status -sb\" and \"git branch -vv\", I'd do it as a separate\nfollow-up patch, where we can discuss the compatibility question\nseparately.\n\nThanks for the review.\n\n"},{"id":"555689","messageId":"20261021072137.258934-1-gitter.spiros@gmail.com","threadId":"66591","inReplyTo":"20261019175722.5223-1-gitter.spiros@gmail.com","subject":"[PATCH v2] status: reword message for a missing upstream branch","fromName":"Elia Pinto","fromEmail":"gitter.spiros@gmail.com","sentAt":"2026-10-21T07:21:37Z","receivedAt":"2026-10-21T07:21:37Z","isPatch":true,"sender":{"key":"gitter.spiros@gmail.com","avatar":"https://avatars.githubusercontent.com/u/158490?v=4"},"body":"Clone an empty repository, make a commit and run \"git status\":\n\n    $ git init --bare empty.git\n    $ git clone empty.git work && cd work\n    $ git commit --allow-empty -m initial\n    $ git status\n    On branch master\n    Your branch is based on 'origin/master', but the upstream is gone.\n      (use \"git branch --unset-upstream\" to fixup)\n\nThe upstream is not gone, it was never there: the remote is empty,\nso origin/master has not been created yet. The advice is also not\nwhat the user needs; \"git push\" creates origin/master and the\nmessage goes away.\n\nThe message was added in f2e087395b (branch: report invalid tracking\nbranch as gone, 2013-08-26), assuming that a configured upstream that\ncannot be resolved must have been deleted. But \"git clone\" of an empty\nrepository configures the upstream anyway, and Git has no way to tell\n\"deleted\" from \"not created yet\".\n\nSince we cannot tell the two cases apart, change the message for both,\nincluding the \"deleted\" case that has been reported as \"gone\" since\n2013, so that it is correct either way:\n\n    Your branch is set up to track 'origin/master', which does not exist.\n      (use \"git push\" to create it)\n      (use \"git branch --unset-upstream\" to stop tracking it)\n\nOnly suggest \"git push\" when it would actually create the upstream,\nthat is when the push destination of the branch (what \"@{push}\"\nresolves to) is the upstream itself. This is not the case, for\nexample, with push.default set to \"nothing\", or when pushing to a\ndifferent remote (branch.<name>.pushRemote or remote.pushDefault).\nIt is also not the case with push.default set to \"matching\": it\nonly pushes branches that already exist on the remote, so it would\nnot create the missing upstream. In all these cases only suggest\n\"git branch --unset-upstream\".\n\npush.default is not used when the remote has its own push refspec or\nis a mirror, though, and then \"git push\" does create the upstream, so\nsuggest it even with push.default set to \"matching\".\n\n\"git checkout\" prints the same message, so it changes too.\n\nLeave the short \"[gone]\" label alone. It is untranslated in\n\"git status --porcelain\" and in \"%(upstream:track)\" of\n\"git for-each-ref\", where it is documented and scripts may parse\nit. It is translated in \"git status -sb\" and \"git branch -vv\", but\nunder the C locale it still reads \"gone\", and recipes like\n\"git branch -vv | grep ': gone]'\" are common. Rewording it can be\ndone separately.\n\nSigned-off-by: Elia Pinto <gitter.spiros@gmail.com>\n---\nChanges since v1:\n\n - push_creates() suggests \"git push\" when the push remote has a push\n   refspec or is a mirror, even with push.default=matching, checking\n   things in the same order as branch_get_push_1(); add tests for\n   both cases.\n\n - Correct the log message about the \"[gone]\" label: it is translated\n   in \"git status -sb\" and \"git branch -vv\", and untranslated only in\n   \"git status --porcelain\" and \"git for-each-ref\".\n\n remote.c                 |  45 +++++++++++--\n t/t6040-tracking-info.sh | 135 ++++++++++++++++++++++++++++++++++++++-\n 2 files changed, 172 insertions(+), 8 deletions(-)\n\ndiff --git a/remote.c b/remote.c\nindex 49ee2ea318..5f703b40a9 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -2449,6 +2449,39 @@ static void format_branch_comparison(struct strbuf *sb,\n \t}\n }\n \n+/*\n+ * Would a plain \"git push\" create the remote-tracking ref \"upstream\"?\n+ * Not with \"matching\", which only updates branches that already exist\n+ * on the remote, unless push refspecs or mirroring override it, as in\n+ * branch_get_push_1().\n+ */\n+static bool push_creates(struct branch *branch, const char *push_ref,\n+\t\t\t const char *upstream)\n+{\n+\tstruct remote *remote;\n+\n+\tif (!push_ref || strcmp(push_ref, upstream))\n+\t\treturn false;\n+\tremote = pushremote_get(pushremote_for_branch(branch, NULL));\n+\tif (remote && (remote->push.nr || remote->mirror))\n+\t\treturn true;\n+\treturn repo_config_values(the_repository)->push_default !=\n+\t       PUSH_DEFAULT_MATCHING;\n+}\n+\n+static void format_missing_upstream(struct strbuf *sb, const char *name,\n+\t\t\t\t    bool suggest_push)\n+{\n+\tstrbuf_addf(sb, _(\"Your branch is set up to track '%s', \"\n+\t\t\t  \"which does not exist.\\n\"), name);\n+\tif (!advice_enabled(ADVICE_STATUS_HINTS))\n+\t\treturn;\n+\tif (suggest_push)\n+\t\tstrbuf_addstr(sb, _(\"  (use \\\"git push\\\" to create it)\\n\"));\n+\tstrbuf_addstr(sb, _(\"  (use \\\"git branch --unset-upstream\\\" \"\n+\t\t\t    \"to stop tracking it)\\n\"));\n+}\n+\n /*\n  * Return true when there is anything to report, otherwise false.\n  */\n@@ -2510,12 +2543,12 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,\n \n \t\tif (cmp < 0) {\n \t\t\tif (is_upstream) {\n-\t\t\t\tstrbuf_addf(sb,\n-\t\t\t\t\t_(\"Your branch is based on '%s', but the upstream is gone.\\n\"),\n-\t\t\t\t\tshort_ref);\n-\t\t\t\tif (advice_enabled(ADVICE_STATUS_HINTS))\n-\t\t\t\t\tstrbuf_addstr(sb,\n-\t\t\t\t\t\t_(\"  (use \\\"git branch --unset-upstream\\\" to fixup)\\n\"));\n+\t\t\t\tbool suggest_push = push_creates(branch,\n+\t\t\t\t\t\t\t\t push_ref,\n+\t\t\t\t\t\t\t\t full_ref);\n+\n+\t\t\t\tformat_missing_upstream(sb, short_ref,\n+\t\t\t\t\t\t\tsuggest_push);\n \t\t\t\treported = 1;\n \t\t\t}\n \t\t\tfree(full_ref);\ndiff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh\nindex e95d420972..7804c84aaf 100755\n--- a/t/t6040-tracking-info.sh\n+++ b/t/t6040-tracking-info.sh\n@@ -96,7 +96,7 @@ test_expect_success 'checkout (upstream is gone)' '\n \t\tcd test &&\n \t\tgit checkout b5\n \t) >actual &&\n-\ttest_grep \"is based on .*, but the upstream is gone.\" actual\n+\ttest_grep \"set up to track .*, which does not exist.\" actual\n '\n \n test_expect_success 'checkout (up-to-date with upstream)' '\n@@ -123,7 +123,138 @@ test_expect_success 'status (upstream is gone)' '\n \t\t# reports nothing to commit\n \t\ttest_must_fail git commit --dry-run\n \t) >actual &&\n-\ttest_grep \"is based on .*, but the upstream is gone.\" actual\n+\ttest_grep \"set up to track .*, which does not exist.\" actual\n+'\n+\n+test_expect_success 'setup clone of an empty repository' '\n+\tgit init --bare empty.git &&\n+\tgit clone empty.git empty-clone &&\n+\tgit -C empty-clone commit --allow-empty -m initial\n+'\n+\n+test_expect_success 'status (upstream not yet pushed after empty clone)' '\n+\tcat >expect <<-EOF &&\n+\tOn branch main\n+\tYour branch is set up to track ${SQ}origin/main${SQ}, which does not exist.\n+\t  (use \"git push\" to create it)\n+\t  (use \"git branch --unset-upstream\" to stop tracking it)\n+\n+\tnothing to commit, working tree clean\n+\tEOF\n+\tgit -C empty-clone status >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'checkout (upstream not yet pushed after empty clone)' '\n+\ttest_when_finished \"git -C empty-clone branch -D tmp\" &&\n+\tcat >expect <<-EOF &&\n+\tYour branch is set up to track ${SQ}origin/main${SQ}, which does not exist.\n+\t  (use \"git push\" to create it)\n+\t  (use \"git branch --unset-upstream\" to stop tracking it)\n+\tEOF\n+\tgit -C empty-clone checkout -b tmp &&\n+\tgit -C empty-clone checkout main >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'status -s -b (upstream not yet pushed after empty clone)' '\n+\techo \"## main...origin/main [gone]\" >expect &&\n+\tgit -C empty-clone status -s -b >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'setup expected output without \"git push\" advice' '\n+\tcat >expect-no-push <<-EOF\n+\tOn branch main\n+\tYour branch is set up to track ${SQ}origin/main${SQ}, which does not exist.\n+\t  (use \"git branch --unset-upstream\" to stop tracking it)\n+\n+\tnothing to commit, working tree clean\n+\tEOF\n+'\n+\n+test_expect_success 'status (missing upstream, push.default=nothing)' '\n+\tgit -C empty-clone -c push.default=nothing status >actual &&\n+\ttest_cmp expect-no-push actual\n+'\n+\n+# \"matching\" only updates branches that already exist on the remote\n+test_expect_success 'status (missing upstream, push.default=matching)' '\n+\tgit -C empty-clone -c push.default=matching status >actual &&\n+\ttest_cmp expect-no-push actual\n+'\n+\n+# but push.default is not used with a push refspec or a mirror\n+test_expect_success 'status (missing upstream, matching with push refspec)' '\n+\tgit -C empty-clone -c push.default=matching \\\n+\t\t-c remote.origin.push=refs/heads/main:refs/heads/main \\\n+\t\tstatus >actual &&\n+\ttest_grep \"use \\\"git push\\\" to create it\" actual\n+'\n+\n+test_expect_success 'status (missing upstream, matching with mirror remote)' '\n+\tgit -C empty-clone -c push.default=matching \\\n+\t\t-c remote.origin.mirror=true \\\n+\t\tstatus >actual &&\n+\ttest_grep \"use \\\"git push\\\" to create it\" actual\n+'\n+\n+test_expect_success 'status (missing upstream, pushRemote is another remote)' '\n+\tgit init --bare fork.git &&\n+\tgit -C empty-clone remote add fork ../fork.git &&\n+\tgit -C empty-clone -c branch.main.pushRemote=fork status >actual &&\n+\ttest_cmp expect-no-push actual\n+'\n+\n+test_expect_success 'status (missing upstream, advice.statusHints=false)' '\n+\tcat >expect <<-EOF &&\n+\tOn branch main\n+\tYour branch is set up to track ${SQ}origin/main${SQ}, which does not exist.\n+\n+\tnothing to commit, working tree clean\n+\tEOF\n+\tgit -C empty-clone -c advice.statusHints=false status >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'setup upstream deleted on the remote and pruned' '\n+\tgit init --bare pruned.git &&\n+\tgit clone pruned.git pruned-clone &&\n+\t(\n+\t\tcd pruned-clone &&\n+\t\tgit commit --allow-empty -m initial &&\n+\t\tgit push origin main &&\n+\t\tgit checkout -b topic &&\n+\t\tgit push -u origin topic\n+\t) &&\n+\tgit -C pruned.git branch -D topic &&\n+\tgit -C pruned-clone fetch --prune\n+'\n+\n+test_expect_success 'status (upstream deleted on the remote and pruned)' '\n+\tcat >expect <<-EOF &&\n+\tOn branch topic\n+\tYour branch is set up to track ${SQ}origin/topic${SQ}, which does not exist.\n+\t  (use \"git push\" to create it)\n+\t  (use \"git branch --unset-upstream\" to stop tracking it)\n+\n+\tnothing to commit, working tree clean\n+\tEOF\n+\tgit -C pruned-clone status >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'short formats still show \"gone\" for a deleted upstream' '\n+\techo \"## topic...origin/topic [gone]\" >expect &&\n+\tgit -C pruned-clone status -s -b >actual &&\n+\ttest_cmp expect actual &&\n+\tgit -C pruned-clone branch -vv >actual &&\n+\ttest_grep \"^\\* topic .* \\[origin/topic: gone\\] initial$\" actual &&\n+\techo \"topic [gone]\" >expect &&\n+\tgit -C pruned-clone for-each-ref \\\n+\t\t--format=\"%(refname:short) %(upstream:track)\" \\\n+\t\trefs/heads/topic >actual &&\n+\ttest_cmp expect actual\n '\n \n test_expect_success 'status (up-to-date with upstream)' '\n-- \n2.53.0\n\n\n"},{"id":"556863","messageId":"20261030090545.9744-1-gitter.spiros@gmail.com","threadId":"66591","inReplyTo":"20261021072137.258934-1-gitter.spiros@gmail.com","subject":"Re: [PATCH v2] status: reword message for a missing upstream branch","fromName":"Elia Pinto","fromEmail":"gitter.spiros@gmail.com","sentAt":"2026-10-30T09:05:45Z","receivedAt":"2026-10-30T09:05:45Z","isPatch":true,"sender":{"key":"gitter.spiros@gmail.com","avatar":"https://avatars.githubusercontent.com/u/158490?v=4"},"body":"Hi,\n\na gentle ping on this one. It is queued in 'seen' as\nep/status-missing-upstream and has been marked \"Needs review\" in the\nlast three issues of \"What's cooking\".\n\nTo recap: after cloning an empty repository, \"git status\" says that\nthe upstream \"is gone\" and suggests \"git branch --unset-upstream\",\nwhile the upstream was simply never created and \"git push\" is what\nthe user needs. The patch rewords the message for a configured\nupstream that does not exist, and suggests \"git push\" only when it\nwould actually create it (i.e. when @{push} is the upstream).\n\nv2 also addresses Junio's note on v1 about the \"[gone]\" label: the\nlog message now says correctly where it is translated, and rewording\nthe label itself is left for a separate patch.\n\nAny review or comment would be appreciated.\n\nThanks,\nElia\n\n"},{"id":"558650","messageId":"20261117212756.716005-1-gitter.spiros@gmail.com","threadId":"66591","inReplyTo":"20261030090545.9744-1-gitter.spiros@gmail.com","subject":"Re: [PATCH v2] status: reword message for a missing upstream branch","fromName":"Elia Pinto","fromEmail":"gitter.spiros@gmail.com","sentAt":"2026-11-17T21:27:56Z","receivedAt":"2026-11-17T21:27:56Z","isPatch":true,"sender":{"key":"gitter.spiros@gmail.com","avatar":"https://avatars.githubusercontent.com/u/158490?v=4"},"body":"Hi Harald, Junio,\n\nA gentle ping on this v2. It has been queued in 'seen' as\nep/status-missing-upstream, and \"What's cooking\" has listed it as\n\"Needs review\" for a while. It still merges cleanly with both master\n(e1ec09b23c) and 'seen'.\n\nAs far as I can tell, v2 addresses the comments Junio made on v1 (the\nshorter \"missing\" he suggested for \"[gone]\" will come as a separate\npatch, as I said in my reply), so what it is missing is a review, but\nplease tell me if I overlooked something.\n\nHarald, you found the idea sensible when you looked at the RFC; would\nyou have time to look at v2? (v1 was a resend of the RFC, not a\nduplicate, as noted below its \"---\".)\n\nIf something needs to change for this to move forward, I will be happy\nto send a v3. If nobody finds the change worth having, that is fine\ntoo: just say so and I will withdraw it, so that it does not linger in\n'seen'.\n\nThanks,\nElia\n\n"},{"id":"558653","messageId":"CAHwyqnXmOFTYLM6Am54SGE7Za9wiVS+0uJQhZfxeomS18COLvg@mail.gmail.com","threadId":"66591","inReplyTo":"20261117212756.716005-1-gitter.spiros@gmail.com","subject":"Re: [PATCH v2] status: reword message for a missing upstream branch","fromName":"Harald Nordgren","fromEmail":"haraldnordgren@gmail.com","sentAt":"2026-11-17T22:03:13Z","receivedAt":"2026-11-17T22:03:13Z","isPatch":true,"sender":{"key":"haraldnordgren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9569897?v=4"},"body":"v2 looks good to me.\n\n\nHarald\n\nOn Tue, Nov 17, 2026 at 10:28 PM Elia Pinto <gitter.spiros@gmail.com> wrote:\n>\n> Hi Harald, Junio,\n>\n> A gentle ping on this v2. It has been queued in 'seen' as\n> ep/status-missing-upstream, and \"What's cooking\" has listed it as\n> \"Needs review\" for a while. It still merges cleanly with both master\n> (e1ec09b23c) and 'seen'.\n>\n> As far as I can tell, v2 addresses the comments Junio made on v1 (the\n> shorter \"missing\" he suggested for \"[gone]\" will come as a separate\n> patch, as I said in my reply), so what it is missing is a review, but\n> please tell me if I overlooked something.\n>\n> Harald, you found the idea sensible when you looked at the RFC; would\n> you have time to look at v2? (v1 was a resend of the RFC, not a\n> duplicate, as noted below its \"---\".)\n>\n> If something needs to change for this to move forward, I will be happy\n> to send a v3. If nobody finds the change worth having, that is fine\n> too: just say so and I will withdraw it, so that it does not linger in\n> 'seen'.\n>\n> Thanks,\n> Elia\n\n"},{"id":"558663","messageId":"xmqqy0ar9gvs.fsf@gitster.g","threadId":"66591","inReplyTo":"CAHwyqnXmOFTYLM6Am54SGE7Za9wiVS+0uJQhZfxeomS18COLvg@mail.gmail.com","subject":"Re: [PATCH v2] status: reword message for a missing upstream branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-17T23:29:11Z","receivedAt":"2026-11-17T23:29:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Harald Nordgren <haraldnordgren@gmail.com> writes:\n\n> v2 looks good to me.\n\nThis and another single liner \"The idea makes sense to me!\" you sent\nto the RFC are both nice encouragements, but does not help assessing\nthe goodness of the patch because it is hard to tell for those\nwatching from the sidelines how deeply the \"reviewer\" actually read\nthe code, understood the issues, before coming up with the verdict.\n\nGiving a positive review is much harder than pointing out issues in\na patch, but we should aim to become better at it.\n\nThanks.\n\n\n"},{"id":"558714","messageId":"xmqq5wxu87es.fsf@gitster.g","threadId":"66591","inReplyTo":"20261021072137.258934-1-gitter.spiros@gmail.com","subject":"Re: [PATCH v2] status: reword message for a missing upstream branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-18T15:51:23Z","receivedAt":"2026-11-18T15:51:23Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Elia Pinto <gitter.spiros@gmail.com> writes:\n\n> Clone an empty repository, make a commit and run \"git status\":\n>\n>     $ git init --bare empty.git\n>     $ git clone empty.git work && cd work\n>     $ git commit --allow-empty -m initial\n>     $ git status\n>     On branch master\n>     Your branch is based on 'origin/master', but the upstream is gone.\n>       (use \"git branch --unset-upstream\" to fixup)\n> ...\n>\n>     Your branch is set up to track 'origin/master', which does not exist.\n>       (use \"git push\" to create it)\n>       (use \"git branch --unset-upstream\" to stop tracking it)\n>\n> Only suggest \"git push\" when it would actually create the upstream,\n> that is when the push destination of the branch (what \"@{push}\"\n> resolves to) is the upstream itself. This is not the case, for\n> example, with push.default set to \"nothing\", or when pushing to a\n> different remote (branch.<name>.pushRemote or remote.pushDefault).\n> It is also not the case with push.default set to \"matching\": it\n> only pushes branches that already exist on the remote, so it would\n> not create the missing upstream. In all these cases only suggest\n> \"git branch --unset-upstream\".\n\nThe earlier discussion has been entirely paged out of my brain, so I\nmight repeat the same question that you have already answered, or I\nmay say contradicting things, but please bear with me.\n\n> diff --git a/remote.c b/remote.c\n> index 49ee2ea318..5f703b40a9 100644\n> --- a/remote.c\n> +++ b/remote.c\n> @@ -2449,6 +2449,39 @@ static void format_branch_comparison(struct strbuf *sb,\n> ...\n> +static bool push_creates(struct branch *branch, const char *push_ref,\n> +\t\t\t const char *upstream)\n> +{\n> +\tstruct remote *remote;\n> +\n> +\tif (!push_ref || strcmp(push_ref, upstream))\n> +\t\treturn false;\n> +\tremote = pushremote_get(pushremote_for_branch(branch, NULL));\n> +\tif (remote && (remote->push.nr || remote->mirror))\n> +\t\treturn true;\n\nUsing --mirror means the local branch we are interested in (e.g.,\n'master' in your example) would be sent to their 'master'.  Do we\nneed to check if their 'master' is what our 'master' is based on,\nthough?  Can our 'master' be tracking their 'main', for example?\n\nWe are content if there exists one or more \"push\" refspecs for the\nremote, regardless of what the value is, but is that really\nsufficient?  What if our push refspec is deliberately narrow to\npublish only selected branches, such as:\n\n           [remote \"origin\"]\n\t\tpush = next\n\t\tpush = seen\n\nand the current branch in question is not among them?\n\n> +\treturn repo_config_values(the_repository)->push_default !=\n> +\t       PUSH_DEFAULT_MATCHING;\n\nYou mentioned \"nothing\" in the log message; shouldn't that also be\nspecial cased?\n\n> +}\n> +\n> +static void format_missing_upstream(struct strbuf *sb, const char *name,\n> +\t\t\t\t    bool suggest_push)\n> +{\n> +\tstrbuf_addf(sb, _(\"Your branch is set up to track '%s', \"\n> +\t\t\t  \"which does not exist.\\n\"), name);\n> +\tif (!advice_enabled(ADVICE_STATUS_HINTS))\n> +\t\treturn;\n> +\tif (suggest_push)\n> +\t\tstrbuf_addstr(sb, _(\"  (use \\\"git push\\\" to create it)\\n\"));\n> +\tstrbuf_addstr(sb, _(\"  (use \\\"git branch --unset-upstream\\\" \"\n> +\t\t\t    \"to stop tracking it)\\n\"));\n> +}\n\nWe see value of suggest_push is only used when the advice is enabled.\n\n> @@ -2510,12 +2543,12 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,\n>  \n>  \t\tif (cmp < 0) {\n>  \t\t\tif (is_upstream) {\n> -\t\t\t\tstrbuf_addf(sb,\n> -\t\t\t\t\t_(\"Your branch is based on '%s', but the upstream is gone.\\n\"),\n> -\t\t\t\t\tshort_ref);\n> -\t\t\t\tif (advice_enabled(ADVICE_STATUS_HINTS))\n> -\t\t\t\t\tstrbuf_addstr(sb,\n> -\t\t\t\t\t\t_(\"  (use \\\"git branch --unset-upstream\\\" to fixup)\\n\"));\n> +\t\t\t\tbool suggest_push = push_creates(branch,\n> +\t\t\t\t\t\t\t\t push_ref,\n> +\t\t\t\t\t\t\t\t full_ref);\n\nBut we call push_creates() to compute suggest_push whether we have\nadvice enabled or declined.  I wonder if it makes the logic flow\ncleaner to give a few more arguments to format_missing_upstream()\nand move push_creates() call there, not here?\n\n> +\t\t\t\tformat_missing_upstream(sb, short_ref,\n> +\t\t\t\t\t\t\tsuggest_push);\n>  \t\t\t\treported = 1;\n>  \t\t\t}\n>  \t\t\tfree(full_ref);\n> diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh\n> index e95d420972..7804c84aaf 100755\n> --- a/t/t6040-tracking-info.sh\n> +++ b/t/t6040-tracking-info.sh\n> @@ -96,7 +96,7 @@ test_expect_success 'checkout (upstream is gone)' '\n>  \t\tcd test &&\n>  \t\tgit checkout b5\n>  \t) >actual &&\n> -\ttest_grep \"is based on .*, but the upstream is gone.\" actual\n> +\ttest_grep \"set up to track .*, which does not exist.\" actual\n>  '\n>  \n>  test_expect_success 'checkout (up-to-date with upstream)' '\n> @@ -123,7 +123,138 @@ test_expect_success 'status (upstream is gone)' '\n>  \t\t# reports nothing to commit\n>  \t\ttest_must_fail git commit --dry-run\n>  \t) >actual &&\n> -\ttest_grep \"is based on .*, but the upstream is gone.\" actual\n> +\ttest_grep \"set up to track .*, which does not exist.\" actual\n> +'\n> +\n> +test_expect_success 'setup clone of an empty repository' '\n> +\tgit init --bare empty.git &&\n> +\tgit clone empty.git empty-clone &&\n> +\tgit -C empty-clone commit --allow-empty -m initial\n> +'\n> +\n> +test_expect_success 'status (upstream not yet pushed after empty clone)' '\n> +\tcat >expect <<-EOF &&\n> +\tOn branch main\n> +\tYour branch is set up to track ${SQ}origin/main${SQ}, which does not exist.\n> +\t  (use \"git push\" to create it)\n> +\t  (use \"git branch --unset-upstream\" to stop tracking it)\n> +\n> +\tnothing to commit, working tree clean\n> +\tEOF\n> +\tgit -C empty-clone status >actual &&\n> +\ttest_cmp expect actual\n> +'\n> +\n> +test_expect_success 'checkout (upstream not yet pushed after empty clone)' '\n> +\ttest_when_finished \"git -C empty-clone branch -D tmp\" &&\n> +\tcat >expect <<-EOF &&\n> +\tYour branch is set up to track ${SQ}origin/main${SQ}, which does not exist.\n> +\t  (use \"git push\" to create it)\n> +\t  (use \"git branch --unset-upstream\" to stop tracking it)\n> +\tEOF\n> +\tgit -C empty-clone checkout -b tmp &&\n> +\tgit -C empty-clone checkout main >actual &&\n> +\ttest_cmp expect actual\n> +'\n> +\n> +test_expect_success 'status -s -b (upstream not yet pushed after empty clone)' '\n> +\techo \"## main...origin/main [gone]\" >expect &&\n> +\tgit -C empty-clone status -s -b >actual &&\n> +\ttest_cmp expect actual\n> +'\n> +\n> +test_expect_success 'setup expected output without \"git push\" advice' '\n> +\tcat >expect-no-push <<-EOF\n> +\tOn branch main\n> +\tYour branch is set up to track ${SQ}origin/main${SQ}, which does not exist.\n> +\t  (use \"git branch --unset-upstream\" to stop tracking it)\n> +\n> +\tnothing to commit, working tree clean\n> +\tEOF\n> +'\n> +\n> +test_expect_success 'status (missing upstream, push.default=nothing)' '\n> +\tgit -C empty-clone -c push.default=nothing status >actual &&\n> +\ttest_cmp expect-no-push actual\n> +'\n> +\n> +# \"matching\" only updates branches that already exist on the remote\n> +test_expect_success 'status (missing upstream, push.default=matching)' '\n> +\tgit -C empty-clone -c push.default=matching status >actual &&\n> +\ttest_cmp expect-no-push actual\n> +'\n> +\n> +# but push.default is not used with a push refspec or a mirror\n> +test_expect_success 'status (missing upstream, matching with push refspec)' '\n> +\tgit -C empty-clone -c push.default=matching \\\n> +\t\t-c remote.origin.push=refs/heads/main:refs/heads/main \\\n> +\t\tstatus >actual &&\n> +\ttest_grep \"use \\\"git push\\\" to create it\" actual\n> +'\n> +\n> +test_expect_success 'status (missing upstream, matching with mirror remote)' '\n> +\tgit -C empty-clone -c push.default=matching \\\n> +\t\t-c remote.origin.mirror=true \\\n> +\t\tstatus >actual &&\n> +\ttest_grep \"use \\\"git push\\\" to create it\" actual\n> +'\n> +\n> +test_expect_success 'status (missing upstream, pushRemote is another remote)' '\n> +\tgit init --bare fork.git &&\n> +\tgit -C empty-clone remote add fork ../fork.git &&\n> +\tgit -C empty-clone -c branch.main.pushRemote=fork status >actual &&\n> +\ttest_cmp expect-no-push actual\n> +'\n> +\n> +test_expect_success 'status (missing upstream, advice.statusHints=false)' '\n> +\tcat >expect <<-EOF &&\n> +\tOn branch main\n> +\tYour branch is set up to track ${SQ}origin/main${SQ}, which does not exist.\n> +\n> +\tnothing to commit, working tree clean\n> +\tEOF\n> +\tgit -C empty-clone -c advice.statusHints=false status >actual &&\n> +\ttest_cmp expect actual\n> +'\n> +\n> +test_expect_success 'setup upstream deleted on the remote and pruned' '\n> +\tgit init --bare pruned.git &&\n> +\tgit clone pruned.git pruned-clone &&\n> +\t(\n> +\t\tcd pruned-clone &&\n> +\t\tgit commit --allow-empty -m initial &&\n> +\t\tgit push origin main &&\n> +\t\tgit checkout -b topic &&\n> +\t\tgit push -u origin topic\n> +\t) &&\n> +\tgit -C pruned.git branch -D topic &&\n> +\tgit -C pruned-clone fetch --prune\n> +'\n> +\n> +test_expect_success 'status (upstream deleted on the remote and pruned)' '\n> +\tcat >expect <<-EOF &&\n> +\tOn branch topic\n> +\tYour branch is set up to track ${SQ}origin/topic${SQ}, which does not exist.\n> +\t  (use \"git push\" to create it)\n> +\t  (use \"git branch --unset-upstream\" to stop tracking it)\n> +\n> +\tnothing to commit, working tree clean\n> +\tEOF\n> +\tgit -C pruned-clone status >actual &&\n> +\ttest_cmp expect actual\n> +'\n> +\n> +test_expect_success 'short formats still show \"gone\" for a deleted upstream' '\n> +\techo \"## topic...origin/topic [gone]\" >expect &&\n> +\tgit -C pruned-clone status -s -b >actual &&\n> +\ttest_cmp expect actual &&\n> +\tgit -C pruned-clone branch -vv >actual &&\n> +\ttest_grep \"^\\* topic .* \\[origin/topic: gone\\] initial$\" actual &&\n> +\techo \"topic [gone]\" >expect &&\n> +\tgit -C pruned-clone for-each-ref \\\n> +\t\t--format=\"%(refname:short) %(upstream:track)\" \\\n> +\t\trefs/heads/topic >actual &&\n> +\ttest_cmp expect actual\n>  '\n>  \n>  test_expect_success 'status (up-to-date with upstream)' '\n\n"},{"id":"558784","messageId":"20261119055026.759205-1-gitter.spiros@gmail.com","threadId":"66591","inReplyTo":"xmqq5wxu87es.fsf@gitster.g","subject":"Re: [PATCH v2] status: reword message for a missing upstream branch","fromName":"Elia Pinto","fromEmail":"gitter.spiros@gmail.com","sentAt":"2026-11-19T05:50:26Z","receivedAt":"2026-11-19T05:50:26Z","isPatch":true,"sender":{"key":"gitter.spiros@gmail.com","avatar":"https://avatars.githubusercontent.com/u/158490?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Using --mirror means the local branch we are interested in (e.g.,\n> 'master' in your example) would be sent to their 'master'.  Do we\n> need to check if their 'master' is what our 'master' is based on,\n> though?  Can our 'master' be tracking their 'main', for example?\n\nThe first check in push_creates() catches that. push_ref is what\n\"@{push}\" resolves to, and for a mirror remote branch_get_push_1() maps\nrefs/heads/master to origin/master. That differs from the upstream\norigin/main, so we return false before looking at the mirror setting.\nWith remote.origin.mirror=true and branch.master.merge=refs/heads/main,\n\"git status\" gives only the \"--unset-upstream\" hint.\n\n> We are content if there exists one or more \"push\" refspecs for the\n> remote, regardless of what the value is, but is that really\n> sufficient?  What if our push refspec is deliberately narrow to\n> publish only selected branches, such as:\n>\n>            [remote \"origin\"]\n> \t\tpush = next\n> \t\tpush = seen\n>\n> and the current branch in question is not among them?\n\nThe same check again: no push refspec matches 'master', so\nbranch_get_push_1() fails with \"push refspecs for 'origin' do not\ninclude 'master'\", push_ref is NULL and we return false. The refspec\nand mirror tests only come into play once we know that @{push} is the\nupstream; they are there because push.default is not consulted at all\nwhen either is set.\n\n> You mentioned \"nothing\" in the log message; shouldn't that also be\n> special cased?\n\nWith push.default=nothing @{push} does not resolve either, so it ends\nup in the same place; 'status (missing upstream, push.default=nothing)'\nin t6040 covers it. \"matching\" is the only mode in which @{push}\nresolves to the upstream although \"git push\" would not create it, hence\nthe special case.\n\nNone of this is said in the comment above push_creates(), which is why\nit raises these questions. In v3 I will spell it out there and add\ntests for the mirror and the narrow refspec cases.\n\n> But we call push_creates() to compute suggest_push whether we have\n> advice enabled or declined.  I wonder if it makes the logic flow\n> cleaner to give a few more arguments to format_missing_upstream()\n> and move push_creates() call there, not here?\n\nYes, that reads better. I will do it in v3.\n\nThanks for the review.\n\n"},{"id":"558786","messageId":"20261119055726.774485-1-gitter.spiros@gmail.com","threadId":"66591","inReplyTo":"20261021072137.258934-1-gitter.spiros@gmail.com","subject":"[PATCH v3] status: reword message for a missing upstream branch","fromName":"Elia Pinto","fromEmail":"gitter.spiros@gmail.com","sentAt":"2026-11-19T05:57:26Z","receivedAt":"2026-11-19T05:57:26Z","isPatch":true,"sender":{"key":"gitter.spiros@gmail.com","avatar":"https://avatars.githubusercontent.com/u/158490?v=4"},"body":"Clone an empty repository, make a commit and run \"git status\":\n\n    $ git init --bare empty.git\n    $ git clone empty.git work && cd work\n    $ git commit --allow-empty -m initial\n    $ git status\n    On branch master\n    Your branch is based on 'origin/master', but the upstream is gone.\n      (use \"git branch --unset-upstream\" to fixup)\n\nThe upstream is not gone, it was never there: the remote is empty,\nso origin/master has not been created yet. The advice is also not\nwhat the user needs; \"git push\" creates origin/master and the\nmessage goes away.\n\nThe message was added in f2e087395b (branch: report invalid tracking\nbranch as gone, 2013-08-26), assuming that a configured upstream that\ncannot be resolved must have been deleted. But \"git clone\" of an empty\nrepository configures the upstream anyway, and Git has no way to tell\n\"deleted\" from \"not created yet\".\n\nSince we cannot tell the two cases apart, change the message for both,\nincluding the \"deleted\" case that has been reported as \"gone\" since\n2013, so that it is correct either way:\n\n    Your branch is set up to track 'origin/master', which does not exist.\n      (use \"git push\" to create it)\n      (use \"git branch --unset-upstream\" to stop tracking it)\n\nOnly suggest \"git push\" when it would actually create the upstream,\nthat is when the push destination of the branch (what \"@{push}\"\nresolves to) is the upstream itself. This is not the case, for\nexample, with push.default set to \"nothing\", or when pushing to a\ndifferent remote (branch.<name>.pushRemote or remote.pushDefault).\nIt is also not the case with push.default set to \"matching\": it\nonly pushes branches that already exist on the remote, so it would\nnot create the missing upstream. In all these cases only suggest\n\"git branch --unset-upstream\".\n\npush.default is not used when the remote has its own push refspec or\nis a mirror, though, and then \"git push\" does create the upstream, so\nsuggest it even with push.default set to \"matching\".\n\n\"git checkout\" prints the same message, so it changes too.\n\nLeave the short \"[gone]\" label alone. It is untranslated in\n\"git status --porcelain\" and in \"%(upstream:track)\" of\n\"git for-each-ref\", where it is documented and scripts may parse\nit. It is translated in \"git status -sb\" and \"git branch -vv\", but\nunder the C locale it still reads \"gone\", and recipes like\n\"git branch -vv | grep ': gone]'\" are common. Rewording it can be\ndone separately.\n\nSigned-off-by: Elia Pinto <gitter.spiros@gmail.com>\n---\nChanges since v2:\n\n - push_creates() is now called from format_missing_upstream(), only\n   when advice.statusHints is enabled.\n\n - The comment above push_creates() explains why requiring @{push} to\n   be the upstream already rules out push.default=nothing, push\n   refspecs that do not cover the branch, and a mirror remote when the\n   branch tracks a branch of a different name.\n\n - Two new tests in t6040 for the last two cases.\n\n remote.c                 |  49 +++++++++++--\n t/t6040-tracking-info.sh | 150 ++++++++++++++++++++++++++++++++++++++-\n 2 files changed, 191 insertions(+), 8 deletions(-)\n\ndiff --git a/remote.c b/remote.c\nindex 49ee2ea318..7e26088f65 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -2449,6 +2449,47 @@ static void format_branch_comparison(struct strbuf *sb,\n \t}\n }\n \n+/*\n+ * Would a plain \"git push\" create the remote-tracking ref \"upstream\"?\n+ *\n+ * Only if \"push_ref\", what @{push} resolves to, is the upstream. That\n+ * rules out push.default=nothing, push refspecs that do not include\n+ * the branch, and pushes that go elsewhere, e.g. a mirror remote when\n+ * the branch tracks a branch of a different name: @{push} does not\n+ * resolve or names another ref.\n+ *\n+ * Even then, \"matching\" only updates branches that already exist on\n+ * the remote, unless push refspecs or mirroring override it, as in\n+ * branch_get_push_1().\n+ */\n+static bool push_creates(struct branch *branch, const char *push_ref,\n+\t\t\t const char *upstream)\n+{\n+\tstruct remote *remote;\n+\n+\tif (!push_ref || strcmp(push_ref, upstream))\n+\t\treturn false;\n+\tremote = pushremote_get(pushremote_for_branch(branch, NULL));\n+\tif (remote && (remote->push.nr || remote->mirror))\n+\t\treturn true;\n+\treturn repo_config_values(the_repository)->push_default !=\n+\t       PUSH_DEFAULT_MATCHING;\n+}\n+\n+static void format_missing_upstream(struct strbuf *sb, struct branch *branch,\n+\t\t\t\t    const char *name, const char *push_ref,\n+\t\t\t\t    const char *upstream)\n+{\n+\tstrbuf_addf(sb, _(\"Your branch is set up to track '%s', \"\n+\t\t\t  \"which does not exist.\\n\"), name);\n+\tif (!advice_enabled(ADVICE_STATUS_HINTS))\n+\t\treturn;\n+\tif (push_creates(branch, push_ref, upstream))\n+\t\tstrbuf_addstr(sb, _(\"  (use \\\"git push\\\" to create it)\\n\"));\n+\tstrbuf_addstr(sb, _(\"  (use \\\"git branch --unset-upstream\\\" \"\n+\t\t\t    \"to stop tracking it)\\n\"));\n+}\n+\n /*\n  * Return true when there is anything to report, otherwise false.\n  */\n@@ -2510,12 +2551,8 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,\n \n \t\tif (cmp < 0) {\n \t\t\tif (is_upstream) {\n-\t\t\t\tstrbuf_addf(sb,\n-\t\t\t\t\t_(\"Your branch is based on '%s', but the upstream is gone.\\n\"),\n-\t\t\t\t\tshort_ref);\n-\t\t\t\tif (advice_enabled(ADVICE_STATUS_HINTS))\n-\t\t\t\t\tstrbuf_addstr(sb,\n-\t\t\t\t\t\t_(\"  (use \\\"git branch --unset-upstream\\\" to fixup)\\n\"));\n+\t\t\t\tformat_missing_upstream(sb, branch, short_ref,\n+\t\t\t\t\t\t\tpush_ref, full_ref);\n \t\t\t\treported = 1;\n \t\t\t}\n \t\t\tfree(full_ref);\ndiff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh\nindex e95d420972..1f0583b391 100755\n--- a/t/t6040-tracking-info.sh\n+++ b/t/t6040-tracking-info.sh\n@@ -96,7 +96,7 @@ test_expect_success 'checkout (upstream is gone)' '\n \t\tcd test &&\n \t\tgit checkout b5\n \t) >actual &&\n-\ttest_grep \"is based on .*, but the upstream is gone.\" actual\n+\ttest_grep \"set up to track .*, which does not exist.\" actual\n '\n \n test_expect_success 'checkout (up-to-date with upstream)' '\n@@ -123,7 +123,153 @@ test_expect_success 'status (upstream is gone)' '\n \t\t# reports nothing to commit\n \t\ttest_must_fail git commit --dry-run\n \t) >actual &&\n-\ttest_grep \"is based on .*, but the upstream is gone.\" actual\n+\ttest_grep \"set up to track .*, which does not exist.\" actual\n+'\n+\n+test_expect_success 'setup clone of an empty repository' '\n+\tgit init --bare empty.git &&\n+\tgit clone empty.git empty-clone &&\n+\tgit -C empty-clone commit --allow-empty -m initial\n+'\n+\n+test_expect_success 'status (upstream not yet pushed after empty clone)' '\n+\tcat >expect <<-EOF &&\n+\tOn branch main\n+\tYour branch is set up to track ${SQ}origin/main${SQ}, which does not exist.\n+\t  (use \"git push\" to create it)\n+\t  (use \"git branch --unset-upstream\" to stop tracking it)\n+\n+\tnothing to commit, working tree clean\n+\tEOF\n+\tgit -C empty-clone status >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'checkout (upstream not yet pushed after empty clone)' '\n+\ttest_when_finished \"git -C empty-clone branch -D tmp\" &&\n+\tcat >expect <<-EOF &&\n+\tYour branch is set up to track ${SQ}origin/main${SQ}, which does not exist.\n+\t  (use \"git push\" to create it)\n+\t  (use \"git branch --unset-upstream\" to stop tracking it)\n+\tEOF\n+\tgit -C empty-clone checkout -b tmp &&\n+\tgit -C empty-clone checkout main >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'status -s -b (upstream not yet pushed after empty clone)' '\n+\techo \"## main...origin/main [gone]\" >expect &&\n+\tgit -C empty-clone status -s -b >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'setup expected output without \"git push\" advice' '\n+\tcat >expect-no-push <<-EOF\n+\tOn branch main\n+\tYour branch is set up to track ${SQ}origin/main${SQ}, which does not exist.\n+\t  (use \"git branch --unset-upstream\" to stop tracking it)\n+\n+\tnothing to commit, working tree clean\n+\tEOF\n+'\n+\n+test_expect_success 'status (missing upstream, push.default=nothing)' '\n+\tgit -C empty-clone -c push.default=nothing status >actual &&\n+\ttest_cmp expect-no-push actual\n+'\n+\n+# \"matching\" only updates branches that already exist on the remote\n+test_expect_success 'status (missing upstream, push.default=matching)' '\n+\tgit -C empty-clone -c push.default=matching status >actual &&\n+\ttest_cmp expect-no-push actual\n+'\n+\n+# but push.default is not used with a push refspec or a mirror\n+test_expect_success 'status (missing upstream, matching with push refspec)' '\n+\tgit -C empty-clone -c push.default=matching \\\n+\t\t-c remote.origin.push=refs/heads/main:refs/heads/main \\\n+\t\tstatus >actual &&\n+\ttest_grep \"use \\\"git push\\\" to create it\" actual\n+'\n+\n+test_expect_success 'status (missing upstream, matching with mirror remote)' '\n+\tgit -C empty-clone -c push.default=matching \\\n+\t\t-c remote.origin.mirror=true \\\n+\t\tstatus >actual &&\n+\ttest_grep \"use \\\"git push\\\" to create it\" actual\n+'\n+\n+test_expect_success 'status (missing upstream, mirror pushes to another name)' '\n+\ttest_when_finished \"git -C empty-clone config branch.main.merge refs/heads/main\" &&\n+\tgit -C empty-clone config branch.main.merge refs/heads/other &&\n+\tgit -C empty-clone -c remote.origin.mirror=true status >actual &&\n+\ttest_grep \"track ${SQ}origin/other${SQ}, which does not exist\" actual &&\n+\ttest_grep ! \"git push\" actual\n+'\n+\n+test_expect_success 'status (missing upstream, push refspecs without the branch)' '\n+\tgit -C empty-clone -c remote.origin.push=refs/heads/next \\\n+\t\t-c remote.origin.push=refs/heads/seen \\\n+\t\tstatus >actual &&\n+\ttest_cmp expect-no-push actual\n+'\n+\n+test_expect_success 'status (missing upstream, pushRemote is another remote)' '\n+\tgit init --bare fork.git &&\n+\tgit -C empty-clone remote add fork ../fork.git &&\n+\tgit -C empty-clone -c branch.main.pushRemote=fork status >actual &&\n+\ttest_cmp expect-no-push actual\n+'\n+\n+test_expect_success 'status (missing upstream, advice.statusHints=false)' '\n+\tcat >expect <<-EOF &&\n+\tOn branch main\n+\tYour branch is set up to track ${SQ}origin/main${SQ}, which does not exist.\n+\n+\tnothing to commit, working tree clean\n+\tEOF\n+\tgit -C empty-clone -c advice.statusHints=false status >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'setup upstream deleted on the remote and pruned' '\n+\tgit init --bare pruned.git &&\n+\tgit clone pruned.git pruned-clone &&\n+\t(\n+\t\tcd pruned-clone &&\n+\t\tgit commit --allow-empty -m initial &&\n+\t\tgit push origin main &&\n+\t\tgit checkout -b topic &&\n+\t\tgit push -u origin topic\n+\t) &&\n+\tgit -C pruned.git branch -D topic &&\n+\tgit -C pruned-clone fetch --prune\n+'\n+\n+test_expect_success 'status (upstream deleted on the remote and pruned)' '\n+\tcat >expect <<-EOF &&\n+\tOn branch topic\n+\tYour branch is set up to track ${SQ}origin/topic${SQ}, which does not exist.\n+\t  (use \"git push\" to create it)\n+\t  (use \"git branch --unset-upstream\" to stop tracking it)\n+\n+\tnothing to commit, working tree clean\n+\tEOF\n+\tgit -C pruned-clone status >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'short formats still show \"gone\" for a deleted upstream' '\n+\techo \"## topic...origin/topic [gone]\" >expect &&\n+\tgit -C pruned-clone status -s -b >actual &&\n+\ttest_cmp expect actual &&\n+\tgit -C pruned-clone branch -vv >actual &&\n+\ttest_grep \"^\\* topic .* \\[origin/topic: gone\\] initial$\" actual &&\n+\techo \"topic [gone]\" >expect &&\n+\tgit -C pruned-clone for-each-ref \\\n+\t\t--format=\"%(refname:short) %(upstream:track)\" \\\n+\t\trefs/heads/topic >actual &&\n+\ttest_cmp expect actual\n '\n \n test_expect_success 'status (up-to-date with upstream)' '\n\nRange-diff against v2:\n1:  e5920906ed ! 1:  0d4dfd06ab status: reword message for a missing upstream branch\n    @@ remote.c: static void format_branch_comparison(struct strbuf *sb,\n      \n     +/*\n     + * Would a plain \"git push\" create the remote-tracking ref \"upstream\"?\n    -+ * Not with \"matching\", which only updates branches that already exist\n    -+ * on the remote, unless push refspecs or mirroring override it, as in\n    ++ *\n    ++ * Only if \"push_ref\", what @{push} resolves to, is the upstream. That\n    ++ * rules out push.default=nothing, push refspecs that do not include\n    ++ * the branch, and pushes that go elsewhere, e.g. a mirror remote when\n    ++ * the branch tracks a branch of a different name: @{push} does not\n    ++ * resolve or names another ref.\n    ++ *\n    ++ * Even then, \"matching\" only updates branches that already exist on\n    ++ * the remote, unless push refspecs or mirroring override it, as in\n     + * branch_get_push_1().\n     + */\n     +static bool push_creates(struct branch *branch, const char *push_ref,\n    @@ remote.c: static void format_branch_comparison(struct strbuf *sb,\n     +\t       PUSH_DEFAULT_MATCHING;\n     +}\n     +\n    -+static void format_missing_upstream(struct strbuf *sb, const char *name,\n    -+\t\t\t\t    bool suggest_push)\n    ++static void format_missing_upstream(struct strbuf *sb, struct branch *branch,\n    ++\t\t\t\t    const char *name, const char *push_ref,\n    ++\t\t\t\t    const char *upstream)\n     +{\n     +\tstrbuf_addf(sb, _(\"Your branch is set up to track '%s', \"\n     +\t\t\t  \"which does not exist.\\n\"), name);\n     +\tif (!advice_enabled(ADVICE_STATUS_HINTS))\n     +\t\treturn;\n    -+\tif (suggest_push)\n    ++\tif (push_creates(branch, push_ref, upstream))\n     +\t\tstrbuf_addstr(sb, _(\"  (use \\\"git push\\\" to create it)\\n\"));\n     +\tstrbuf_addstr(sb, _(\"  (use \\\"git branch --unset-upstream\\\" \"\n     +\t\t\t    \"to stop tracking it)\\n\"));\n    @@ remote.c: int format_tracking_info(struct branch *branch, struct strbuf *sb,\n     -\t\t\t\tif (advice_enabled(ADVICE_STATUS_HINTS))\n     -\t\t\t\t\tstrbuf_addstr(sb,\n     -\t\t\t\t\t\t_(\"  (use \\\"git branch --unset-upstream\\\" to fixup)\\n\"));\n    -+\t\t\t\tbool suggest_push = push_creates(branch,\n    -+\t\t\t\t\t\t\t\t push_ref,\n    -+\t\t\t\t\t\t\t\t full_ref);\n    -+\n    -+\t\t\t\tformat_missing_upstream(sb, short_ref,\n    -+\t\t\t\t\t\t\tsuggest_push);\n    ++\t\t\t\tformat_missing_upstream(sb, branch, short_ref,\n    ++\t\t\t\t\t\t\tpush_ref, full_ref);\n      \t\t\t\treported = 1;\n      \t\t\t}\n      \t\t\tfree(full_ref);\n    @@ t/t6040-tracking-info.sh: test_expect_success 'status (upstream is gone)' '\n     +\ttest_grep \"use \\\"git push\\\" to create it\" actual\n     +'\n     +\n    ++test_expect_success 'status (missing upstream, mirror pushes to another name)' '\n    ++\ttest_when_finished \"git -C empty-clone config branch.main.merge refs/heads/main\" &&\n    ++\tgit -C empty-clone config branch.main.merge refs/heads/other &&\n    ++\tgit -C empty-clone -c remote.origin.mirror=true status >actual &&\n    ++\ttest_grep \"track ${SQ}origin/other${SQ}, which does not exist\" actual &&\n    ++\ttest_grep ! \"git push\" actual\n    ++'\n    ++\n    ++test_expect_success 'status (missing upstream, push refspecs without the branch)' '\n    ++\tgit -C empty-clone -c remote.origin.push=refs/heads/next \\\n    ++\t\t-c remote.origin.push=refs/heads/seen \\\n    ++\t\tstatus >actual &&\n    ++\ttest_cmp expect-no-push actual\n    ++'\n    ++\n     +test_expect_success 'status (missing upstream, pushRemote is another remote)' '\n     +\tgit init --bare fork.git &&\n     +\tgit -C empty-clone remote add fork ../fork.git &&\n\nbase-commit: 47fdf2208c5b94c8cc01c106b8f7c85efb91c926\n-- \n2.53.0\n\n\n"},{"id":"558863","messageId":"xmqqik1szsce.fsf@gitster.g","threadId":"66591","inReplyTo":"20261119055026.759205-1-gitter.spiros@gmail.com","subject":"Re: [PATCH v2] status: reword message for a missing upstream branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-19T16:41:37Z","receivedAt":"2026-11-19T16:41:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Elia Pinto <gitter.spiros@gmail.com> writes:\n\n> The same check again: no push refspec matches 'master', so\n> branch_get_push_1() fails with \"push refspecs for 'origin' do not\n> include 'master'\", push_ref is NULL and we return false. The refspec\n> and mirror tests only come into play once we know that @{push} is the\n> upstream; they are there because push.default is not consulted at all\n> when either is set.\n\nAhh, that is where the trickiness lies.  So the \"mirror or has any\npush refspec\" check is about \"should we check what the default say?\"\n\nThat may deserve a comment, as you said below.\n\n>> You mentioned \"nothing\" in the log message; shouldn't that also be\n>> special cased?\n>\n> With push.default=nothing @{push} does not resolve either, so it ends\n> up in the same place; 'status (missing upstream, push.default=nothing)'\n> in t6040 covers it. \"matching\" is the only mode in which @{push}\n> resolves to the upstream although \"git push\" would not create it, hence\n> the special case.\n>\n> None of this is said in the comment above push_creates(), which is why\n> it raises these questions. In v3 I will spell it out there and add\n> tests for the mirror and the narrow refspec cases.\n>\n>> But we call push_creates() to compute suggest_push whether we have\n>> advice enabled or declined.  I wonder if it makes the logic flow\n>> cleaner to give a few more arguments to format_missing_upstream()\n>> and move push_creates() call there, not here?\n>\n> Yes, that reads better. I will do it in v3.\n>\n> Thanks for the review.\n\nThanks.\n\n"},{"id":"558871","messageId":"xmqqjym8y9vy.fsf@gitster.g","threadId":"66591","inReplyTo":"20261119055726.774485-1-gitter.spiros@gmail.com","subject":"Re: [PATCH v3] status: reword message for a missing upstream branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-19T18:05:37Z","receivedAt":"2026-11-19T18:05:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Elia Pinto <gitter.spiros@gmail.com> writes:\n\n> diff --git a/remote.c b/remote.c\n> index 49ee2ea318..7e26088f65 100644\n> --- a/remote.c\n> +++ b/remote.c\n> @@ -2449,6 +2449,47 @@ static void format_branch_comparison(struct strbuf *sb,\n>  \t}\n>  }\n>  \n> +/*\n> + * Would a plain \"git push\" create the remote-tracking ref \"upstream\"?\n> + *\n> + * Only if \"push_ref\", what @{push} resolves to, is the upstream. That\n> + * rules out push.default=nothing, push refspecs that do not include\n> + * the branch, and pushes that go elsewhere, e.g. a mirror remote when\n> + * the branch tracks a branch of a different name: @{push} does not\n> + * resolve or names another ref.\n> + *\n> + * Even then, \"matching\" only updates branches that already exist on\n> + * the remote, unless push refspecs or mirroring override it, as in\n> + * branch_get_push_1().\n> + */\n> +static bool push_creates(struct branch *branch, const char *push_ref,\n> +\t\t\t const char *upstream)\n> +{\n> +\tstruct remote *remote;\n> +\n> +\tif (!push_ref || strcmp(push_ref, upstream))\n> +\t\treturn false;\n> +\tremote = pushremote_get(pushremote_for_branch(branch, NULL));\n> +\tif (remote && (remote->push.nr || remote->mirror))\n> +\t\treturn true;\n> +\treturn repo_config_values(the_repository)->push_default !=\n> +\t       PUSH_DEFAULT_MATCHING;\n> +}\n> +\n> +static void format_missing_upstream(struct strbuf *sb, struct branch *branch,\n> +\t\t\t\t    const char *name, const char *push_ref,\n> +\t\t\t\t    const char *upstream)\n> +{\n> +\tstrbuf_addf(sb, _(\"Your branch is set up to track '%s', \"\n> +\t\t\t  \"which does not exist.\\n\"), name);\n> +\tif (!advice_enabled(ADVICE_STATUS_HINTS))\n> +\t\treturn;\n> +\tif (push_creates(branch, push_ref, upstream))\n> +\t\tstrbuf_addstr(sb, _(\"  (use \\\"git push\\\" to create it)\\n\"));\n> +\tstrbuf_addstr(sb, _(\"  (use \\\"git branch --unset-upstream\\\" \"\n> +\t\t\t    \"to stop tracking it)\\n\"));\n> +}\n\nOK.  This kills two birds with one stone.  An early return based on\nADVICE_STATUS_HINTS omits the call to push_creates() that is only\nrelevant when giving the advance, and the overly long lines in the\ncaller due to a deeply nested block are now much more readable.\n\n>  /*\n>   * Return true when there is anything to report, otherwise false.\n>   */\n> @@ -2510,12 +2551,8 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,\n>  \n>  \t\tif (cmp < 0) {\n>  \t\t\tif (is_upstream) {\n> -\t\t\t\tstrbuf_addf(sb,\n> -\t\t\t\t\t_(\"Your branch is based on '%s', but the upstream is gone.\\n\"),\n> -\t\t\t\t\tshort_ref);\n> -\t\t\t\tif (advice_enabled(ADVICE_STATUS_HINTS))\n> -\t\t\t\t\tstrbuf_addstr(sb,\n> -\t\t\t\t\t\t_(\"  (use \\\"git branch --unset-upstream\\\" to fixup)\\n\"));\n> +\t\t\t\tformat_missing_upstream(sb, branch, short_ref,\n> +\t\t\t\t\t\t\tpush_ref, full_ref);\n>  \t\t\t\treported = 1;\n>  \t\t\t}\n>  \t\t\tfree(full_ref);\n\nWhen the push.default configuration is set to 'upstream', and the\nbranch.<name>.pushRemote (or remote.pushDefault) configuration is\nset to a remote that is different from branch.<name>.remote, because\n\"git push\" would detect misconfiguration and immediately abort like\n\n    fatal: You are pushing to remote '<remote>', which is not the\n    upstream of your current branch '<name>', without telling me\n    what to push to update which remote branch.\n\nYet, we suggest '(use \"git push\" to create it)' with the advice, it\nseems (reproduction added at the end).\n\nbranch_get_push_1() returns the upstream for PUSH_DEFAULT_UPSTREAM\nwithout checking whether the push remote matches the upstream\nremote, and that is what comes back from branch_get_push() and\nstored in push_ref.\n\npush_creates() checks !remote->push.nr and !remote->mirror and\npush_default != PUSH_DEFAULT_MATCHING to decide if \"git push\" would\ncreate the upstream we want, which says \"yes\" unfortunately in this\nsituation.\n\nBut in builtin/push.c, setup_default_push_refspecs() has a guard\n\"if (!same_remote)\" in PUSH_DEFAULT_UPSTREAM before allowing the\nbranch to be used as the destination.  That is what makes the advice\nmessage incorrect in this case.\n\nI am not sure what the right fix should be.\n\nIntuitively, the correct change may be to update branch_get_push_1()\nto pay attention to the remote being the same (in other words, we\nare not in a triangular workflow), as that would match what \"git\npush\" does.  Such a change, however, may have fallouts and break\nother callers of branch_get_push() that have been assuming the\ncurrent behaviour.\n\nAdding a band-aid guard to push_creates() to specifically detect\nthis particular case would be safer, but it is far less satisfactory\nand makes me feel dirty, playing whack-a-mole with the code.\n\nPerhaps branch_get_push_simple(), which is a relatively recent\naddition, might point us in a good direction? \n\nI dunno.\n\n t/t6040-tracking-info.sh | 8 ++++++++\n 1 file changed, 8 insertions(+)\n\ndiff --git c/t/t6040-tracking-info.sh w/t/t6040-tracking-info.sh\nindex 1f0583b391..4752559280 100755\n--- c/t/t6040-tracking-info.sh\n+++ w/t/t6040-tracking-info.sh\n@@ -221,6 +221,14 @@ test_expect_success 'status (missing upstream, pushRemote is another remote)' '\n \ttest_cmp expect-no-push actual\n '\n \n+test_expect_success 'status (missing upstream, push.default=upstream with pushRemote)' '\n+\ttest_must_fail git -C empty-clone -c push.default=upstream \\\n+\t\t-c branch.main.pushRemote=fork push &&\n+\tgit -C empty-clone -c push.default=upstream \\\n+\t\t-c branch.main.pushRemote=fork status >actual &&\n+\ttest_cmp expect-no-push actual\n+'\n+\n test_expect_success 'status (missing upstream, advice.statusHints=false)' '\n \tcat >expect <<-EOF &&\n \tOn branch main\n\n"}]}