4

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.

TamaMcGlinn
  • 2,840
  • 23
  • 34

1 Answers1

4
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'.

TamaMcGlinn
  • 2,840
  • 23
  • 34
  • 1
    I believe you have found the solution but your answer mentions different branches `feature/combined_reporter` compared to your question `feature/aunit_reporters` – hultqvist Mar 11 '21 at 19:14
  • thanks @hultqvist that was confusing indeed. I also added another trick I learned since I wrote this answer. – TamaMcGlinn Mar 12 '21 at 08:30