How to Retrieve notes from the remote repository (Git)

Reginald LynchOctober 31st 2020, 5:00

we need another clone from the local clone we already have. This is to show the push and fetch mechanism of Git with git notes.

Step 1 : Start by checking out the master branch:

git checkout master

Step 2 : Now, create a local branch of all the stable-3.1 branches:

git branch stable-3.1 origin/stable-3.1

Step 3 : We are checking out all these branches because we want to clone this repository and, by default, all the refs/heads/* branches will be cloned. So, when we clone the jgit directory, you will see that we only get the branches we see if you execute git branch:

git branch

Step 4 : Now, go one directory up so that you can create your new clone from the jgit directory:

cd ..
git clone ./jgit shareNotes

Step 5 : Now, enter the shareNotes directory and run git branch -a to see that the only remote branches we have are the branches we checked out as local branches in the jgit directory. After this, we are ready to fetch some notes:

cd shareNotes
git branch -a

Step 6 : We start by showing that we did not receive the notes during the clone:

git log -1 b4f07df357fccdff891df2a4fa5c5bd9e83b4a4a --notes=notesByCategory

Step 7 : As expected, the output does not show the note, and the first line makes it clear why. In the jgit directory, we will see the note. To enable the notes to be fetched, we need to create a new fetch rule configuration; it needs to be similar to the fetch rule for refs/heads. Take a look at the configuration from git config:

git config --get remote.origin.fetch

Step 8 : This shows that we are fetching refs/heads into the refs/remotes/origin reference, but what we also want to do is fetch refs/notes/* into refs/notes/*

git config --add remote.origin.fetch '+refs/notes/*:refs/notes/*'

Step 9 : You should now have it configured. If you leave out the --add option from your command, you will overwrite your current settings. Verify that the rule now exists:

git config --get-all  remote.origin.fetch

Step 10 : Now, try and fetch the notes:

git fetch

Step 11 : As the Git output indicates, we have received some new refs. So, let's check whether we have the note on the commit now:

git log -1 b4f07df357fccdff891df2a4fa5c5bd9e83b4a4a --notes=notesByCategory