Git pull bundle file gives 'fatal: Couldn't find remote ref HEAD'

2.3k Views Asked by At

I'm posting a self-answer because I know some of my colleagues will be googling this soon. We sometimes need to distribute bundle files which are baselined on master and hence only contain the particular branches explicitly included when it was created. For example, the distributor does:

git bundle create ../file.gitbundle master..feature/aunit_reporters

The problem is, after receiving a bundle file, doing git pull ../file.gitbundle gives:

fatal: Couldn't find remote ref HEAD

I've verified the bundle file should be applicable, by:

git bundle verify ../file.gitbundle
The bundle contains this ref:
4f969119b208b71f4893222810600862 refs/heads/feature/aunit_reporters
The bundle requires this ref:
fd9801b79b56f5dd55ab1e6500f16daf

and git show fd9801b79b56f5dd55ab1e6500f16daf correctly displays the commit needed, instead of giving fatal: ambiguous argument '[commit-hash]': unknown revision or path not in the working tree, which would signal that I don't have the necessary baseline commit.

1

There are 1 best solutions below

2
TamaMcGlinn On
git pull ../file.gitbundle feature/aunit_reporters

The second parameter to git pull [remote] is optional and defaults to 'HEAD'. This is the case whether you are using a bundle file or not, but normally real git repositories (local and hosted) have a HEAD pointing somewhere, so the default works. Partial bundle files may not have this; the distributor should really have added HEAD, to allow a regular pull:

git bundle create ../file.gitbundle master..feature/aunit_reporters feature/aunit_reporters HEAD

(unfortunately you have to specify the branchname twice now, otherwise you get a detached HEAD repository, which is equally if not more confusing to the recipient)

The solution is to specify the second parameter as one of the branches that is output by the git bundle verify command, in your case 'feature/aunit_reporters'.