Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetch git notes when cloning

Tags:

git

git-notes

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 ?

like image 865
Zitrax Avatar asked Jun 21 '16 10:06

Zitrax


People also ask

Does git clone fetch all tags?

When you clone a repository, all the tags associated with the repository will be pulled down. To fetch all the remote tags, use the fetch command as shown below. You can list down all the tags from the git repository using the following command.

How do I view notes in git?

Notes can be shown by git log along with the original commit message. To distinguish these notes from the message stored in the commit object, the notes are indented like the message, after an unindented line saying "Notes (<refname>):" (or "Notes:" for refs/notes/commits ).

What is the difference between git clone pull and fetch?

When comparing Git pull vs fetch, Git fetch is a safer alternative because it pulls in all the commits from your remote but doesn't make any changes to your local files. On the other hand, Git pull is faster as you're performing multiple actions in one – a better bang for your buck.

Are git notes pushed?

Like tags, notes aren't pushed by default. Notes aren't fetched by default.


1 Answers

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.)

like image 138
torek Avatar answered Oct 25 '22 16:10

torek