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

[PATCH v3 0/2] branch/push: suggest intended form when remote/branch slip given

From
Harald Nordgren via GitGitGadget <gitgitgadget@gmail.com>
Date
Jun 27, 2026, 18:02 UTC
Message-ID
<pull.2331.v3.git.git.1782583345.gitgitgadget@gmail.com>
In-Reply-To
<pull.2331.v2.git.git.1782338114.gitgitgadget@gmail.com>

When the repository or upstream argument is a slip like "origin/main" or "origin main", suggest the intended "git push origin main" or "git branch --set-upstream-to=origin/main" form instead of failing with an unrelated error.

Changes in v3:
 * Reworded the branch commit message to also show the second confusing
   error (the requested upstream branch 'origin' does not exist) for when
   the operated-on branch does exist.
 * Converted the new t5529 tests from bare grep/! grep to test_grep to fix
   the test-lint failures.
 * Added a brief call-site comment explaining the up-front advice_enabled()
   gate (skips the lookups when the hint is off, while advise_if_enabled()
   still prints the disable-message footer).
Changes in v2:
 * Rewrote both commit messages to lead with the intended command, the easy
   slip, and the resulting error, instead of the terse original.
 * Gated each suggestion on advice_enabled() up front, so a user who
   silenced the hint pays no remote/ref lookups and falls through to the
   original error. Extracted the detection logic into helpers
   (die_if_repo_looks_like_ref, die_if_upstream_looks_like_remote) so each
   call site reads as a single guarded line.
Harald Nordgren (2):
  branch: suggest <remote>/<branch> on upstream slip
  push: suggest <remote> <branch> for a slash slip
 Documentation/config/advice.adoc |  5 +++++
 advice.c                         |  1 +
 advice.h                         |  1 +
 builtin/branch.c                 | 32 +++++++++++++++++++++++++++
 builtin/push.c                   | 37 ++++++++++++++++++++++++++++++-
 t/t3200-branch.sh                | 38 ++++++++++++++++++++++++++++++++
 t/t5529-push-errors.sh           | 31 ++++++++++++++++++++++++++
 7 files changed, 144 insertions(+), 1 deletion(-)
base-commit: ab776a62a78576513ee121424adb19597fbb7613
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2331%2FHaraldNordgren%2Fsuggest-remote-branch-slips-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2331/HaraldNordgren/suggest-remote-branch-slips-v3
Pull-Request: https://github.com/git/git/pull/2331
Range-diff vs v2:
 1:  11bcecebf4 ! 1:  9883c28482 branch: suggest <remote>/<branch> on upstream slip
     @@ Commit message
      
              fatal: branch 'main' does not exist
      
     -    pointing at a branch the user never meant to name.
     +    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:
     @@ builtin/branch.c: int cmd_branch(int argc,
       		if (!refs_ref_exists(get_main_ref_store(the_repository), branch->refname)) {
       			if (!argc || branch_checked_out(branch->refname))
       				die(_("no commit on branch '%s' yet"), branch->name);
     ++			/*
     ++			 * Check the advice up front to avoid the ref
     ++			 * lookups when the hint is off. The helper still
     ++			 * calls advise_if_enabled() so the hint carries the
     ++			 * standard "disable this message" instructions.
     ++			 */
      +			if (argc == 1 &&
      +			    advice_enabled(ADVICE_SET_UPSTREAM_FAILURE))
      +				die_if_upstream_looks_like_remote(new_upstream, argv[0]);
 2:  49de5a925d ! 2:  dbe4dbc346 push: suggest <remote> <branch> for a slash slip
     @@ builtin/push.c: int cmd_push(int argc,
       		if (!add_remote_or_group(repo, &remote_group)) {
      +			struct remote *r;
      +
     ++			/*
     ++			 * Check the advice up front to avoid the remote
     ++			 * lookup when the hint is off. The helper still
     ++			 * calls advise_if_enabled() so the hint carries the
     ++			 * standard "disable this message" instructions.
     ++			 */
      +			if (advice_enabled(ADVICE_PUSH_REPO_LOOKS_LIKE_REF))
      +				die_if_repo_looks_like_ref(repo);
      +
     @@ t/t5529-push-errors.sh: test_expect_success 'detect empty remote with targeted r
       
      +test_expect_success 'suggest <remote> <branch> for a <remote>/<branch> slip' '
      +	test_must_fail git push origin/main 2>stderr &&
     -+	grep "${SQ}origin/main${SQ} is not a valid push target" stderr &&
     -+	grep "hint: Did you mean to use: git push origin main?" stderr &&
     ++	test_grep "${SQ}origin/main${SQ} is not a valid push target" stderr &&
     ++	test_grep "hint: Did you mean to use: git push origin main?" stderr &&
      +	test_must_fail git -c advice.pushRepoLooksLikeRef=false push origin/main 2>stderr &&
     -+	! grep "Did you mean" stderr
     ++	test_grep ! "Did you mean" stderr
      +'
      +
      +test_expect_success 'suggest <remote> <branch> when the branch has slashes' '
      +	test_must_fail git push origin/feature/x 2>stderr &&
     -+	grep "hint: Did you mean to use: git push origin feature/x?" stderr
     ++	test_grep "hint: Did you mean to use: git push origin feature/x?" stderr
      +'
      +
      +test_expect_success 'no suggestion when prefix is not a configured remote' '
      +	test_must_fail git push not-a-remote/main 2>stderr &&
     -+	! grep "Did you mean" stderr
     ++	test_grep ! "Did you mean" stderr
      +'
      +
      +test_expect_success 'no suggestion for a trailing slash with no branch' '
      +	test_must_fail git push origin/ 2>stderr &&
     -+	! grep "Did you mean" stderr
     ++	test_grep ! "Did you mean" stderr
      +'
      +
      +test_expect_success 'no suggestion when the argument is an existing path' '
      +	test_when_finished "rm -rf origin" &&
      +	git init --bare origin/main &&
      +	git push origin/main HEAD:refs/heads/pushed 2>stderr &&
     -+	! grep "Did you mean" stderr &&
     ++	test_grep ! "Did you mean" stderr &&
      +	git -C origin/main rev-parse --verify refs/heads/pushed
      +'
      +
-- 
gitgitgadget
Previous: Junio C HamanoNext: Harald Nordgren via GitGitGadget
Message 22 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.