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

Re: [PATCH 2/2] push: suggest <remote> <branch> for a slash slip

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 22, 2026, 20:40 UTC
Message-ID
<xmqqtsqus40t.fsf@gitster.g>
In-Reply-To
<ea1412b1107f485cf52c953e387a513d95d82b53.1781262619.git.gitgitgadget@gmail.com>
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 5 quoted lines
> From: Harald Nordgren <haraldnordgren@gmail.com>
>
> "git push origin/main" is treated as a repository and dies with
> "'origin/main' does not appear to be a git repository", with no hint
> that a space was meant instead of a slash.

This is easier for me to guess than what the user may have wanted to do in the decription of [1/2]. But it still will be easier on readers to say

    When pusing out up update the "main" branch to the remote
    "origin", i.e.,
        $ git push origin main
    it is easy for some users to mistakenly say
        $ git push origin/main
    instead.  This however instructs to push to remote "origin/main"
    with configured refspecs, which means a completely different
    thing.  Lucikly, often origin/main does not exist as a remote
    and the command fails without doing any harm, but still may
    leave the user puzzled what happened.  Give hint to ...
or something like that.
> When the argument is not an existing path or configured remote but its
> part before the first slash names one, suggest the intended
> "git push <remote> <branch>" form. The suggestion is shown as advice so
> it can be silenced with advice.pushRepoLooksLikeRef.
Sounds sensible.
Show 24 quoted lines
>  	if (repo) {
>  		if (!add_remote_or_group(repo, &remote_group)) {
> +			const char *slash = strchr(repo, '/');
> +			struct remote *r;
> +
> +			/*
> +			 * A "<remote>/<branch>" argument that does not name
> +			 * a path is likely a slip for the separate
> +			 * "<remote> <branch>" form, so suggest that instead.
> +			 */
> +			if (slash && slash[1] && !file_exists(repo)) {
> +				struct strbuf name = STRBUF_INIT;
> +
> +				strbuf_add(&name, repo, slash - repo);
> +				if (remote_is_configured(remote_get(name.buf), 0)) {
> +					int code = die_message(_("'%s' is not a valid push target"), repo);
> +					advise_if_enabled(ADVICE_PUSH_REPO_LOOKS_LIKE_REF,
> +							  _("Did you mean to use: git push %s %s?"),
> +							  name.buf, slash + 1);
> +					strbuf_release(&name);
> +					exit(code);
> +				}
> +				strbuf_release(&name);
> +			}

Hmph, if this class of hint is not enabled, do we still have to spend cycles on these "is this a remote? is the first token a remote?" computation? I would have expected that a change here would be a two-liner:

    if (!add_remote_or_group(...)) {
+	if (advise_enabled(ADVICE_PUSH_REPO_LOOKS_LIKE_REF))
+		die_if_plausible_typo(...);
	... do the "try treating it as a direct URL or path" thing ...
    }

with the bulk of the "if it has slash, it is not a file, then advise and die" logic inside the new helper function.

What I find especially troubling is that even when advise for this class of hint is not enabled, the new code will hit the new exit(), without falling back to the "try treating it as a direct URL or path" thing. Or am I missing something?

Thanks.
Previous: Harald Nordgren via GitGitGadgetNext: Harald Nordgren
Message 7 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.