it seems like there is no proper documentation regarding git notes. I have added some notes to one of the commit using git notes add command. but when i push the commit, and later do a separate clone, i dont see the note message there. Is there a way to push all the note messages added via git notes command?
Asked
Active
Viewed 1.5k times
1 Answers
73
Push all notes:
git push <remote> refs/notes/*
Fetch all notes:
git fetch origin refs/notes/*:refs/notes/*
Rob Bednark
- 22,937
- 20
- 77
- 112
simont
- 62,662
- 17
- 112
- 131
-
when i do a git pull, it does a merge and then Merge commit 'refs/notes/commits' and then creates a new commit.. why is that so? – Iowa Aug 16 '13 at 09:10
-
1@user2663585 From `man git-pull`: "git-pull - Fetch from and merge with another repository or a branch". `git pull` does both `git fetch` and `git merge`, so if the remote you pull from has commits you don't, you'll do a merge (which makes a new commit). To avoid this, if you want to examine what you'll merge with (instead of doing it all in one), you can run `git fetch`, then `git merge` yourself. – simont Aug 16 '13 at 09:38
-
1Here is what i did, i created a test file, added, committed and pushed it.. then i created a note for that commit and did a note push using "git push origin refs/notes/*".. after that i did a "git checkout master" and did a "git pull origin refs/notes/*:refs/notes/*".. Even though my local repo was in sync with remote central repo, it created a merge commit.. and when i did a git log, it showed 2 more entries, one saying "Notes added by git nodes add" and the 2nd one says "Merge commit 'refs/notes/commits'".. Does this mean, that the git notes internaly does a commit??? pls help me undestand – Iowa Aug 16 '13 at 10:49
-
7@user2663585: Yes, notes are commits, but *not on the branch they point to*. The problem is that `git pull origin blah` means merge `blah` into **your current branch**, even when blah is `refs/notes/commits`. So you merged the notes into your main branch, instead of leaving them off to the side where they belong. – torek Aug 16 '13 at 11:31
-
Don't use that fetch command, remember "You never do your own development on branches that appear on the right hand side of a
"? It applies here as well, if you already have other notes in the local repository at first it won't work, and when you'll likely add a '+' before sure that this way they'll be merged, you'll lose all your local notes (well no, they just get pushed a little into the reflog, if you enabled it, no big deal!! ). – gbr Oct 21 '15 at 11:56 -
2The only way to have this feature somewhat "working" is to put them in another 'namespace' (where the f*ck are these namespaces defined, by the way?) _inside_ refs/notes, for example in refs/notes/origin/ (otherwise `git notes merge` won't do anything - not even error out). So use `git fetch origin refs/notes/*:refs/notes/origin/*` - and then merge them with your local notes. – gbr Oct 21 '15 at 11:56
-
22To always get notes when pulling one can add `fetch = +refs/notes/*:refs/notes/*` to the remote origin section in the git config. – Zitrax Apr 03 '16 at 19:06
-
5To always *push* notes add `push = +refs/notes/*:refs/notes/*` to the remote origin section in the Git config. – Kenny Evitt May 11 '18 at 19:55
-
3@Zitrax that causes git to force-update your local notes, thus overwriting any locally added notes whenever you `git fetch`. (Can of course recover with `git reflog notes/commits`) – derobert Feb 12 '19 at 21:15
-
2If you encounter `zsh: no matches found: refs/notes/*` error, consider quoting the argument: `git push origin 'refs/notes/*'` – Slava Semushin Jan 16 '20 at 20:05