So far, we have been creating notes in our own local repository, which is okay. But if we want to share those notes, we have to be sure to be able to push them. We would also like to be able to retrieve other people's notes from the remote repository. Unfortunately, this is not so plain and simple.
Before we can start, 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
:
$ git checkout master Checking out files: 100% (1529/1529), done. Switched to branch 'master' Your branch is up-to-date with 'origin/master'.
stable-3.x
branches:$ git branch stable-3.0 origin/stable-3.0 Branch stable-3.0 set up to track remote branch stable-3.0 from origin. $ git branch stable-3.1 origin/stable-3.1 Branch stable-3.1 set up to track remote branch stable-3.1 from origin. $ git branch stable-3.2 origin/stable-3.2 Branch stable-3.2 set up to track remote branch stable-3.2 from origin.
refs/heads/*
branches will be cloned. So, when we clone the chapter5
directory, you will see that we only get the branches we see if you execute git branch
:$ git branch * master myNotes notesMessage notesReference stable-3.0 stable-3.1 stable-3.2
chapter5
directory:cd .. $ git clone ./chapter5 shareNotes Cloning into 'shareNotes'... done.
shareNotes
directory and run git branch -a
to see that the only remote branches we have are the branches we had checked out as local branches in the chapter5
directory. After this, we are ready to fetch some notes:cd shareNotes $ git branch -a * master remotes/origin/HEAD -> origin/master remotes/origin/master remotes/origin/myNotes remotes/origin/notesMessage remotes/origin/notesReference remotes/origin/stable-3.0 remotes/origin/stable-3.1 remotes/origin/stable-3.2
chapter5
directory.We have now prepared the setup to push and fetch notes. The challenge is that Git is not a default setup to retrieve and push notes, so you won't usually see other people's notes:
$ git log -1 b4f07df357fccdff891df2a4fa5c5bd9e83b4a4a --notes=alsoCherryPick warning: notes ref refs/notes/alsoCherryPick is invalid commit b4f07df357fccdff891df2a4fa5c5bd9e83b4a4a Author: Matthias Sohn <[email protected]> Date: Tue Sep 24 09:11:47 2013 +0200 Prepare re-signing pgm's ueberjar to avoid SecurityException
chapter5
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 +refs/heads/*:refs/remotes/origin/*
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/*'
--add
option from your command, you will overwrite your current settings. Verify that the rule now exists:$ git config --get-all remote.origin.fetch +refs/heads/*:refs/remotes/origin/* +refs/notes/*:refs/notes/*
$ git fetch From c:/Users/Rasmus/repos/./chapter5 * branch master -> FETCH_HEAD * [new ref] refs/notes/alsoCherryPick -> refs/notes/alsoCherryPick * [new ref] refs/notes/commits -> refs/notes/commits * [new ref] refs/notes/defect -> refs/notes/defect * [new ref] refs/notes/defects -> refs/notes/defects
$ git log -1 b4f07df357fccdff891df2a4fa5c5bd9e83b4a4a --notes=alsoCherryPick commit b4f07df357fccdff891df2a4fa5c5bd9e83b4a4a Author: Matthias Sohn <[email protected]> Date: Tue Sep 24 09:11:47 2013 +0200 Prepare re-signing pgm's ueberjar to avoid SecurityException More output... Signed-off-by: Matthias Sohn <[email protected]> Notes (alsoCherryPick): 570bba5
We fetched the notes. The reason why it works is because of the way we fetched. By default, Git is configured to fetch refs/heads/*
into refs/remotes/origin/*
. This way, we can easily keep track of what is remote and what is local. The branches in our local repo are in refs/heads/*
. These branches are also listed when you execute git branch
.
For notes, we need to fetch refs/notes/*
into refs/notes/*
since we want to get the notes from the server and use them with the git show
, git log
, and git notes
Git commands.