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

Re: Confusing git pull error message

From
Jeff King <peff@peff.net>
Date
Sep 12, 2009, 21:11 UTC
Message-ID
<20090912211119.GA30966@coredump.intra.peff.net>
In-Reply-To
<43d8ce650909121301i4450489dhf475ff6894394a5f@mail.gmail.com>
On Sat, Sep 12, 2009 at 11:01:45PM +0300, John Tapsell wrote:
Show 14 quoted lines
>   So anyway, I tried to do a "git pull" and it gives me the misleading error:
> 
> You asked me to pull without telling me which branch you
> want to merge with, and 'branch.master.merge' in
> your configuration file does not tell me either.  Please
> name which branch you want to merge on the command line and
> try again (e.g. 'git pull <repository> <refspec>').
> See git-pull(1) for details on the refspec.
>
> [...]
>
> But the actual problem is that "master" doesn't exist on origin.  So
> basically I _have_ told it what branch.master.remote and
> branch.master.merge etc is, it's just that they don't appear to exist.

Ugh. That is horrible. It's an artifact of the (IMHO) brain-dead way that pull and fetch interact.

Pull doesn't actually look at the configuration at all. It just calls fetch, and then fetch writes out a file containing the refs it pulled, some of which may be marked with a magic "not-for-merge" flag. So we see that nothing is available for merging and guess that it must not have been configured. Which is of course wrong in your case; it just didn't exist.

I think it is enough for git-pull to just check whether the config exists, and if so, guess that the ref was simply not fetched. IOW, this:

-- >8 --
Subject: [PATCH] pull: make "nothing to merge" error message more accurate

When pull sees that no branches are available for merge and that we have a current branch, it assumes the problem is that we had no branch.*.merge configuration. But it may also be the case that we simply didn't pull the configured ref (probably because it doesn't exist). Let's distinguish those two cases.

Signed-off-by: Jeff King <peff@peff.net>
---
 git-pull.sh |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/git-pull.sh b/git-pull.sh
index 0bbd5bf..4ddd537 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -89,6 +89,9 @@ error_on_no_merge_candidates () {
 	done
 
 	curr_branch=${curr_branch#refs/heads/}
+	upstream=`git config "branch.$curr_branch.merge" ||
+		  git config "branch.$curr_branch.rebase"`
+	upstream_short=`echo "$upstream" | sed "s|refs/heads/||"`
 
 	if [ -z "$curr_branch" ]; then
 		echo "You are not currently on a branch, so I cannot use any"
@@ -96,7 +99,7 @@ error_on_no_merge_candidates () {
 		echo "Please specify which branch you want to merge on the command"
 		echo "line and try again (e.g. 'git pull <repository> <refspec>')."
 		echo "See git-pull(1) for details."
-	else
+	elif [ -z "$upstream" ]; then
 		echo "You asked me to pull without telling me which branch you"
 		echo "want to merge with, and 'branch.${curr_branch}.merge' in"
 		echo "your configuration file does not tell me either.	Please"
@@ -114,6 +117,10 @@ error_on_no_merge_candidates () {
 		echo "    remote.<nickname>.fetch = <refspec>"
 		echo
 		echo "See git-config(1) for details."
+	else
+		echo "Your configuration specified for us to pull the ref"
+		echo "'$upstream_short', but we were unable to fetch it from"
+		echo "the remote."
 	fi
 	exit 1
 }
-- 
1.6.5.rc0.201.g76b4d.dirty
Previous: John TapsellNext: John Tapsell
Message 2 of 28 in “Confusing git pull error message”
  1. John TapsellSep 12, 2009
  2. Jeff KingSep 12, 2009
  3. John TapsellSep 12, 2009
  4. Jeff KingSep 12, 2009
  5. Sverre RabbelierSep 12, 2009
  6. Jeff KingSep 12, 2009
  7. Sverre RabbelierSep 12, 2009
  8. Junio C HamanoSep 13, 2009
  9. Jeff KingSep 13, 2009
  10. Junio C HamanoSep 13, 2009
  11. Jeff KingSep 13, 2009
  12. Junio C HamanoSep 13, 2009
  13. John TapsellSep 13, 2009
  14. Junio C HamanoSep 13, 2009
  15. Junio C HamanoSep 13, 2009
  16. Jeff KingSep 13, 2009
  17. Jeff KingSep 14, 2009
  18. Johannes SixtOct 5, 2009
  19. Jeff KingOct 5, 2009
  20. Johannes SixtOct 5, 2009
  21. Junio C HamanoOct 5, 2009
  22. Jeff KingOct 5, 2009
  23. Jeff KingOct 5, 2009
  24. Nanako ShiraishiOct 8, 2009
  25. Junio C HamanoOct 9, 2009
  26. Junio C HamanoOct 10, 2009
  27. Junio C HamanoOct 5, 2009
  28. Jeff KingOct 5, 2009

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.