13

I know that git notes can be fetched after cloning using:

git fetch origin refs/notes/*:refs/notes/*

or even be setup in git config to be always fetched.

However at clone time I do not get the notes, so I have to clone and then fetch. Although I do see that using --mirror when cloning does get notes too. However my optimal setup would be that I could clone any repository without doing a mirror (since it implies --bare and would also get other unwanted refs) and get the notes too.

Is there any way to setup for example git config to fetch specific additional refs at clone time ?

Zitrax
  • 19,036
  • 20
  • 88
  • 110

1 Answers1

10

The short answer is "no": at clone time, you have your choice of either cloning with the default refspec (+refs/heads/*:refs/remotes/$remote/*, where $remote is replaced with origin or the remote name you select) or with the --mirror fetch-mirror refspec (+refs/*:refs/*). As you note, --mirror implies --bare, and is probably not desirable here.

It would be easy enough to write a shell script that does a clone, then does git config --add remote.origin.fetch "+refs/notes/*:refs/notes/*", then runs git fetch, so that you need not run three commands yourself. (Whether you want the + here, and/or to rename their notes to some other reference name, is up to you. For the FreeBSD repository, I use fetch = +refs/notes/*:refs/notes/origin/* and set notesRef = refs/notes/origin/commits, a practice I copied from elsewhere without thinking about it too much—and so far I have had no reason to rethink or change it.)

Kristian
  • 3,283
  • 3
  • 28
  • 52
torek
  • 448,244
  • 59
  • 642
  • 775
  • Thanks for the explanation. I was amazed there's no `git clone --with-notes` that automatically does this. I should probably submit a patch... – Craig Ringer Oct 26 '18 at 04:44
  • Some people have mentioned you can pass extra refspecs to `--config` when you clone, but a (known) bug causes clone to ignore them. Haven't tested. Hacky anyway. – Craig Ringer Oct 26 '18 at 07:11
  • @CraigRinger: that's annoying. Clone has some code to re-read the config file created during the init-and-config steps; I wonder why that doesn't take care of the refspecs. (Clone is essentially a C coded version of "init, then config, then fetch, then checkout".) – torek Oct 26 '18 at 15:25
  • 3
    @CraigRinger I am writing to you from the future (2020) and still there is no `git clone --with-notes` :( – guneysus May 16 '20 at 11:19