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

Re: [PATCH v2] status: reword message for a missing upstream branch

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 18, 2026, 15:51 UTC
Message-ID
<xmqq5wxu87es.fsf@gitster.g>
In-Reply-To
<20261021072137.258934-1-gitter.spiros@gmail.com>
Elia Pinto <gitter.spiros@gmail.com> writes:
Show 24 quoted lines
> Clone an empty repository, make a commit and run "git status":
>
>     $ git init --bare empty.git
>     $ git clone empty.git work && cd work
>     $ git commit --allow-empty -m initial
>     $ git status
>     On branch master
>     Your branch is based on 'origin/master', but the upstream is gone.
>       (use "git branch --unset-upstream" to fixup)
> ...
>
>     Your branch is set up to track 'origin/master', which does not exist.
>       (use "git push" to create it)
>       (use "git branch --unset-upstream" to stop tracking it)
>
> Only suggest "git push" when it would actually create the upstream,
> that is when the push destination of the branch (what "@{push}"
> resolves to) is the upstream itself. This is not the case, for
> example, with push.default set to "nothing", or when pushing to a
> different remote (branch.<name>.pushRemote or remote.pushDefault).
> It is also not the case with push.default set to "matching": it
> only pushes branches that already exist on the remote, so it would
> not create the missing upstream. In all these cases only suggest
> "git branch --unset-upstream".

The earlier discussion has been entirely paged out of my brain, so I might repeat the same question that you have already answered, or I may say contradicting things, but please bear with me.

Show 16 quoted lines
> diff --git a/remote.c b/remote.c
> index 49ee2ea318..5f703b40a9 100644
> --- a/remote.c
> +++ b/remote.c
> @@ -2449,6 +2449,39 @@ static void format_branch_comparison(struct strbuf *sb,
> ...
> +static bool push_creates(struct branch *branch, const char *push_ref,
> +			 const char *upstream)
> +{
> +	struct remote *remote;
> +
> +	if (!push_ref || strcmp(push_ref, upstream))
> +		return false;
> +	remote = pushremote_get(pushremote_for_branch(branch, NULL));
> +	if (remote && (remote->push.nr || remote->mirror))
> +		return true;

Using --mirror means the local branch we are interested in (e.g., 'master' in your example) would be sent to their 'master'. Do we need to check if their 'master' is what our 'master' is based on, though? Can our 'master' be tracking their 'main', for example?

We are content if there exists one or more "push" refspecs for the remote, regardless of what the value is, but is that really sufficient? What if our push refspec is deliberately narrow to publish only selected branches, such as:

           [remote "origin"]
		push = next
		push = seen
and the current branch in question is not among them?
> +	return repo_config_values(the_repository)->push_default !=
> +	       PUSH_DEFAULT_MATCHING;

You mentioned "nothing" in the log message; shouldn't that also be special cased?

Show 14 quoted lines
> +}
> +
> +static void format_missing_upstream(struct strbuf *sb, const char *name,
> +				    bool suggest_push)
> +{
> +	strbuf_addf(sb, _("Your branch is set up to track '%s', "
> +			  "which does not exist.\n"), name);
> +	if (!advice_enabled(ADVICE_STATUS_HINTS))
> +		return;
> +	if (suggest_push)
> +		strbuf_addstr(sb, _("  (use \"git push\" to create it)\n"));
> +	strbuf_addstr(sb, _("  (use \"git branch --unset-upstream\" "
> +			    "to stop tracking it)\n"));
> +}
We see value of suggest_push is only used when the advice is enabled.
Show 13 quoted lines
> @@ -2510,12 +2543,12 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,
>  
>  		if (cmp < 0) {
>  			if (is_upstream) {
> -				strbuf_addf(sb,
> -					_("Your branch is based on '%s', but the upstream is gone.\n"),
> -					short_ref);
> -				if (advice_enabled(ADVICE_STATUS_HINTS))
> -					strbuf_addstr(sb,
> -						_("  (use \"git branch --unset-upstream\" to fixup)\n"));
> +				bool suggest_push = push_creates(branch,
> +								 push_ref,
> +								 full_ref);

But we call push_creates() to compute suggest_push whether we have advice enabled or declined. I wonder if it makes the logic flow cleaner to give a few more arguments to format_missing_upstream() and move push_creates() call there, not here?

Show 158 quoted lines
> +				format_missing_upstream(sb, short_ref,
> +							suggest_push);
>  				reported = 1;
>  			}
>  			free(full_ref);
> diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh
> index e95d420972..7804c84aaf 100755
> --- a/t/t6040-tracking-info.sh
> +++ b/t/t6040-tracking-info.sh
> @@ -96,7 +96,7 @@ test_expect_success 'checkout (upstream is gone)' '
>  		cd test &&
>  		git checkout b5
>  	) >actual &&
> -	test_grep "is based on .*, but the upstream is gone." actual
> +	test_grep "set up to track .*, which does not exist." actual
>  '
>  
>  test_expect_success 'checkout (up-to-date with upstream)' '
> @@ -123,7 +123,138 @@ test_expect_success 'status (upstream is gone)' '
>  		# reports nothing to commit
>  		test_must_fail git commit --dry-run
>  	) >actual &&
> -	test_grep "is based on .*, but the upstream is gone." actual
> +	test_grep "set up to track .*, which does not exist." actual
> +'
> +
> +test_expect_success 'setup clone of an empty repository' '
> +	git init --bare empty.git &&
> +	git clone empty.git empty-clone &&
> +	git -C empty-clone commit --allow-empty -m initial
> +'
> +
> +test_expect_success 'status (upstream not yet pushed after empty clone)' '
> +	cat >expect <<-EOF &&
> +	On branch main
> +	Your branch is set up to track ${SQ}origin/main${SQ}, which does not exist.
> +	  (use "git push" to create it)
> +	  (use "git branch --unset-upstream" to stop tracking it)
> +
> +	nothing to commit, working tree clean
> +	EOF
> +	git -C empty-clone status >actual &&
> +	test_cmp expect actual
> +'
> +
> +test_expect_success 'checkout (upstream not yet pushed after empty clone)' '
> +	test_when_finished "git -C empty-clone branch -D tmp" &&
> +	cat >expect <<-EOF &&
> +	Your branch is set up to track ${SQ}origin/main${SQ}, which does not exist.
> +	  (use "git push" to create it)
> +	  (use "git branch --unset-upstream" to stop tracking it)
> +	EOF
> +	git -C empty-clone checkout -b tmp &&
> +	git -C empty-clone checkout main >actual &&
> +	test_cmp expect actual
> +'
> +
> +test_expect_success 'status -s -b (upstream not yet pushed after empty clone)' '
> +	echo "## main...origin/main [gone]" >expect &&
> +	git -C empty-clone status -s -b >actual &&
> +	test_cmp expect actual
> +'
> +
> +test_expect_success 'setup expected output without "git push" advice' '
> +	cat >expect-no-push <<-EOF
> +	On branch main
> +	Your branch is set up to track ${SQ}origin/main${SQ}, which does not exist.
> +	  (use "git branch --unset-upstream" to stop tracking it)
> +
> +	nothing to commit, working tree clean
> +	EOF
> +'
> +
> +test_expect_success 'status (missing upstream, push.default=nothing)' '
> +	git -C empty-clone -c push.default=nothing status >actual &&
> +	test_cmp expect-no-push actual
> +'
> +
> +# "matching" only updates branches that already exist on the remote
> +test_expect_success 'status (missing upstream, push.default=matching)' '
> +	git -C empty-clone -c push.default=matching status >actual &&
> +	test_cmp expect-no-push actual
> +'
> +
> +# but push.default is not used with a push refspec or a mirror
> +test_expect_success 'status (missing upstream, matching with push refspec)' '
> +	git -C empty-clone -c push.default=matching \
> +		-c remote.origin.push=refs/heads/main:refs/heads/main \
> +		status >actual &&
> +	test_grep "use \"git push\" to create it" actual
> +'
> +
> +test_expect_success 'status (missing upstream, matching with mirror remote)' '
> +	git -C empty-clone -c push.default=matching \
> +		-c remote.origin.mirror=true \
> +		status >actual &&
> +	test_grep "use \"git push\" to create it" actual
> +'
> +
> +test_expect_success 'status (missing upstream, pushRemote is another remote)' '
> +	git init --bare fork.git &&
> +	git -C empty-clone remote add fork ../fork.git &&
> +	git -C empty-clone -c branch.main.pushRemote=fork status >actual &&
> +	test_cmp expect-no-push actual
> +'
> +
> +test_expect_success 'status (missing upstream, advice.statusHints=false)' '
> +	cat >expect <<-EOF &&
> +	On branch main
> +	Your branch is set up to track ${SQ}origin/main${SQ}, which does not exist.
> +
> +	nothing to commit, working tree clean
> +	EOF
> +	git -C empty-clone -c advice.statusHints=false status >actual &&
> +	test_cmp expect actual
> +'
> +
> +test_expect_success 'setup upstream deleted on the remote and pruned' '
> +	git init --bare pruned.git &&
> +	git clone pruned.git pruned-clone &&
> +	(
> +		cd pruned-clone &&
> +		git commit --allow-empty -m initial &&
> +		git push origin main &&
> +		git checkout -b topic &&
> +		git push -u origin topic
> +	) &&
> +	git -C pruned.git branch -D topic &&
> +	git -C pruned-clone fetch --prune
> +'
> +
> +test_expect_success 'status (upstream deleted on the remote and pruned)' '
> +	cat >expect <<-EOF &&
> +	On branch topic
> +	Your branch is set up to track ${SQ}origin/topic${SQ}, which does not exist.
> +	  (use "git push" to create it)
> +	  (use "git branch --unset-upstream" to stop tracking it)
> +
> +	nothing to commit, working tree clean
> +	EOF
> +	git -C pruned-clone status >actual &&
> +	test_cmp expect actual
> +'
> +
> +test_expect_success 'short formats still show "gone" for a deleted upstream' '
> +	echo "## topic...origin/topic [gone]" >expect &&
> +	git -C pruned-clone status -s -b >actual &&
> +	test_cmp expect actual &&
> +	git -C pruned-clone branch -vv >actual &&
> +	test_grep "^\* topic .* \[origin/topic: gone\] initial$" actual &&
> +	echo "topic [gone]" >expect &&
> +	git -C pruned-clone for-each-ref \
> +		--format="%(refname:short) %(upstream:track)" \
> +		refs/heads/topic >actual &&
> +	test_cmp expect actual
>  '
>  
>  test_expect_success 'status (up-to-date with upstream)' '
Previous: Junio C HamanoNext: Elia Pinto
Message 10 of 14 in “status: reword message for a missing upstream branch”
  1. status: reword message for a missing upstream branchElia Pinto, Oct 19, 2026
  2. Harald NordgrenOct 19, 2026
  3. Junio C HamanoOct 19, 2026
  4. Elia PintoOct 20, 2026
  5. status: reword message for a missing upstream branchElia Pinto, Oct 21, 2026
  6. Elia PintoOct 30, 2026
  7. Elia PintoNov 17, 2026
  8. Harald NordgrenNov 17, 2026
  9. Junio C HamanoNov 17, 2026
  10. Junio C HamanoNov 18, 2026
  11. Elia PintoNov 19, 2026
  12. Junio C HamanoNov 19, 2026
  13. status: reword message for a missing upstream branchElia Pinto, Nov 19, 2026
  14. Junio C HamanoNov 19, 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.