{"thread":{"id":"60071","subject":"Git Commit Notes (fetching/pushing)","startedAt":"2023-08-06T18:36:14Z","lastAt":"2023-08-07T20:18:51Z","messageCount":7,"participants":["Brooke Kuhlmann","Taylor Blau","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"480199","messageId":"D01976C3-4B91-464B-ACF0-78DFFB066747@alchemists.io","threadId":"60071","inReplyTo":null,"subject":"Git Commit Notes (fetching/pushing)","fromName":"Brooke Kuhlmann","fromEmail":"brooke@alchemists.io","sentAt":"2023-08-06T18:35:50Z","receivedAt":"2023-08-06T18:36:14Z","isPatch":false,"sender":{"key":"brooke@alchemists.io","avatar":"https://gravatar.com/avatar/4bd27d52fe87760d2bde1d384f0139eb81013709a0cf27ce654d48a7852727fa?d=mp&s=160"},"body":"I'm noticing issues with GitHub and GitLab when fetching and pushing commit notes and wanted to know if there is a correct way to configure my Git configuration for working with these servers (or maybe notes aren't supported at al)?\n\nHere's my configuration:\n\n```\n[notes]\n  rewriteRef = refs/notes/commits\n\n[remote \"origin\"]\n  fetch = +refs/notes/*:refs/notes/*\n  push = +refs/notes/*:refs/notes/*\n```\n\nUpon creating a note (i.e. `git notes add`) and then pushing changes to the remote, I'll see the following response from GitHub:\n\n``` \nEnumerating objects: 3, done.\nCounting objects: 100% (3/3), done.\nDelta compression using up to 8 threads\nCompressing objects: 100% (2/2), done.\nWriting objects: 100% (2/2), 289 bytes | 289.00 KiB/s, done.\nTotal 2 (delta 1), reused 0 (delta 0), pack-reused 0\nremote: Resolving deltas: 100% (1/1), completed with 1 local object.\nTo https://github.com/bkuhlmann/test\n   5811bd44c32b..0f2422597c5d  refs/notes/commits -> refs/notes/commits\n```\n\nOnly problem is the notes are not pushed. In fact, the feature branch I'm working is never updated. Only when removing my `[remote \"origin\"]` Git configuration does the GitHub server work properly (i.e. my changes are pushed to the remote server...but without any notes). Strangely, in all cases GitHub answers back with a success message even though that is incorrect.\n\nAnyway, if anyone has advice or additional information how this should work (or if my configuration is wrong), I'd be grateful. 🙇🏻‍♂️\n\n\n\n\n"},{"id":"480200","messageId":"ZM/9+YyOAbWWXQtC@nand.local","threadId":"60071","inReplyTo":"D01976C3-4B91-464B-ACF0-78DFFB066747@alchemists.io","subject":"Re: Git Commit Notes (fetching/pushing)","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2023-08-06T20:09:29Z","receivedAt":"2023-08-06T20:09:35Z","isPatch":false,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Sun, Aug 06, 2023 at 12:35:50PM -0600, Brooke Kuhlmann wrote:\n> I'm noticing issues with GitHub and GitLab when fetching and pushing\n> commit notes and wanted to know if there is a correct way to configure\n> my Git configuration for working with these servers (or maybe notes\n> aren't supported at al)?\n>\n> Here's my configuration:\n>\n> ```\n> [notes]\n>   rewriteRef = refs/notes/commits\n>\n> [remote \"origin\"]\n>   fetch = +refs/notes/*:refs/notes/*\n>   push = +refs/notes/*:refs/notes/*\n> ```\n\nIt looks like your refspec may not be doing what you think it is.\n\nHere, you set both the default fetch and push refspecs to\n\"+refs/notes/*:refs/notes/*\" which means to update anything under\nthe \"refs/notes\" hierarchy on either side, even when the updates are not\nfast forwards.\n\nSince you overwrote the default refspec, you end up only pushing the\nnotes, which we see from the response that you got back from GitHub:\n\n> remote: Resolving deltas: 100% (1/1), completed with 1 local object.\n> To https://github.com/bkuhlmann/test\n>    5811bd44c32b..0f2422597c5d  refs/notes/commits -> refs/notes/commits\n\nIndeed, refs/notes/commits is updated on your bkuhlmann/test repository,\nwhich I can fetch from:\n\n    $ git remote add origin git@github.com:bkuhlmann/test.git\n    $ git fetch origin 'refs/notes/*:refs/notes/*'\n    remote: Enumerating objects: 41, done.\n    remote: Counting objects: 100% (41/41), done.\n    remote: Compressing objects: 100% (29/29), done.\n    remote: Total 41 (delta 14), reused 34 (delta 7), pack-reused 0\n    Unpacking objects: 100% (41/41), 4.66 KiB | 1.55 MiB/s, done.\n    From github.com:bkuhlmann/test\n     * [new ref]           refs/notes/commits -> refs/notes/commits\n\nI suspect you want an additional refspec that gathers any branches or\ntags that you want to push along with refs/notes/*.\n\nThanks,\nTaylor\n"},{"id":"480201","messageId":"3A1AEE32-4A0C-445D-A1D8-146CDCA03563@alchemists.io","threadId":"60071","inReplyTo":"ZM/9+YyOAbWWXQtC@nand.local","subject":"Re: Git Commit Notes (fetching/pushing)","fromName":"Brooke Kuhlmann","fromEmail":"brooke@alchemists.io","sentAt":"2023-08-06T21:49:22Z","receivedAt":"2023-08-06T21:49:38Z","isPatch":false,"sender":{"key":"brooke@alchemists.io","avatar":"https://gravatar.com/avatar/4bd27d52fe87760d2bde1d384f0139eb81013709a0cf27ce654d48a7852727fa?d=mp&s=160"},"body":"Hey Taylor. Thanks. Is there a way to configure the pushing of notes for ALL repositories? Basically, I'd like to configure this once (via my global Git configuration) and know that notes are being pushed and fetched across all repositories without having to configure each repository individually.\n\nOriginally, I was trying to use my test repository as a proving ground. I think I understand why only my notes were being pushed but not sure I understand why the default fetch and push refs were overwritten? I thought each fetch/push configuration entry was additive but I guess that's not the case?\n\nHere's my complete local configuration in case it helps:\n\n[core]\nrepositoryformatversion = 0\nfilemode = true\nbare = false\nlogallrefupdates = true\nignorecase = true\nprecomposeunicode = true\n[remote \"origin\"]\nurl = https://github.com/bkuhlmann/test\nfetch = +refs/heads/*:refs/remotes/origin/*\n[branch \"main\"]\nremote = origin\nmerge = refs/heads/main\nrebase = true\n\nI was hoping to update the remote \"origin\" as:\n\n[remote \"origin\"]\nurl = https://github.com/bkuhlmann/test\nfetch = +refs/heads/*:refs/remotes/origin/*\n        fetch = +refs/notes/*:refs/notes/*\n        push = +refs/notes/*:refs/notes/*\n\n...but the addition of the push configuration entry makes it impossible to push the feature branch up. Only the notes are pushed, like you said. ...but I'm missing the connection as to why default branch push behavior is being ignored/overwritten. I'm also failing to find documentation on why I can't create a branch, add some commits, add some notes, and then push all of these changes up (as well as fetch them back down again).\n\n> On Aug 6, 2023, at 2:09 PM, Taylor Blau <me@ttaylorr.com> wrote:\n> \n> On Sun, Aug 06, 2023 at 12:35:50PM -0600, Brooke Kuhlmann wrote:\n>> I'm noticing issues with GitHub and GitLab when fetching and pushing\n>> commit notes and wanted to know if there is a correct way to configure\n>> my Git configuration for working with these servers (or maybe notes\n>> aren't supported at al)?\n>> \n>> Here's my configuration:\n>> \n>> ```\n>> [notes]\n>>  rewriteRef = refs/notes/commits\n>> \n>> [remote \"origin\"]\n>>  fetch = +refs/notes/*:refs/notes/*\n>>  push = +refs/notes/*:refs/notes/*\n>> ```\n> \n> It looks like your refspec may not be doing what you think it is.\n> \n> Here, you set both the default fetch and push refspecs to\n> \"+refs/notes/*:refs/notes/*\" which means to update anything under\n> the \"refs/notes\" hierarchy on either side, even when the updates are not\n> fast forwards.\n> \n> Since you overwrote the default refspec, you end up only pushing the\n> notes, which we see from the response that you got back from GitHub:\n> \n>> remote: Resolving deltas: 100% (1/1), completed with 1 local object.\n>> To https://github.com/bkuhlmann/test\n>>   5811bd44c32b..0f2422597c5d  refs/notes/commits -> refs/notes/commits\n> \n> Indeed, refs/notes/commits is updated on your bkuhlmann/test repository,\n> which I can fetch from:\n> \n>    $ git remote add origin git@github.com:bkuhlmann/test.git\n>    $ git fetch origin 'refs/notes/*:refs/notes/*'\n>    remote: Enumerating objects: 41, done.\n>    remote: Counting objects: 100% (41/41), done.\n>    remote: Compressing objects: 100% (29/29), done.\n>    remote: Total 41 (delta 14), reused 34 (delta 7), pack-reused 0\n>    Unpacking objects: 100% (41/41), 4.66 KiB | 1.55 MiB/s, done.\n>    From github.com:bkuhlmann/test\n>     * [new ref]           refs/notes/commits -> refs/notes/commits\n> \n> I suspect you want an additional refspec that gathers any branches or\n> tags that you want to push along with refs/notes/*.\n> \n> Thanks,\n> Taylor\n\n\n"},{"id":"480202","messageId":"xmqqwmy7irsd.fsf@gitster.g","threadId":"60071","inReplyTo":"3A1AEE32-4A0C-445D-A1D8-146CDCA03563@alchemists.io","subject":"Re: Git Commit Notes (fetching/pushing)","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-08-07T01:07:30Z","receivedAt":"2023-08-07T01:07:38Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Brooke Kuhlmann <brooke@alchemists.io> writes:\n\n> ... o why default branch push behavior is being\n> ignored/overwritten.\n\nThe root of your confusion lies around here, I think.  The \"default\"\nbranch push behaviour is given only when you do not customize.  Once\nyou add customization, you would specify _exactly_ what you want.\n\nIn other words, the customization is NOT something you tell Git to\ndo _in addition to_ what it does anyway (otherwise you would not be\nable to configure _away_ what is usually done by default when you do\nnot want to see it done).\n\n"},{"id":"480213","messageId":"2301E39E-B70D-485B-AFA8-F8DA64B366A2@alchemists.io","threadId":"60071","inReplyTo":"xmqqwmy7irsd.fsf@gitster.g","subject":"Re: Git Commit Notes (fetching/pushing)","fromName":"Brooke Kuhlmann","fromEmail":"brooke@alchemists.io","sentAt":"2023-08-07T14:02:46Z","receivedAt":"2023-08-07T14:04:18Z","isPatch":false,"sender":{"key":"brooke@alchemists.io","avatar":"https://gravatar.com/avatar/4bd27d52fe87760d2bde1d384f0139eb81013709a0cf27ce654d48a7852727fa?d=mp&s=160"},"body":"Thanks Junio. Yep, I see where I went wrong now and learned something new in the process.\n\nI ended up using the following configuration in order to explicitly fetch/push branches, notes, and tags:\n\n[remote \"origin\"]\n\turl = https://github.com/bkuhlmann/test\n\tfetch = +refs/heads/*:refs/remotes/origin/*\n\tfetch = +refs/notes/*:refs/notes/*\n\tfetch = +refs/tags/*:refs/tags/*\n\tpush = +refs/heads/*:refs/remotes/origin/*\n\tpush = +refs/notes/*:refs/notes/*\n\tpush = +refs/tags/*:refs/tags/*\n\nThe only problem is my feature branch never shows up on the remote. If I amend my commits, rebase them, and/or update the commit notes, the changes, once pushed, don't show up on the remote repository. I do see this in the output:\n\nTo https://github.com/bkuhlmann/test\n   709004099276..1eefe6a1101c  refs/notes/commits -> refs/notes/commits\n + a966604d7864...e0a75df6084f release -> origin/release (forced update)\n\nSeeing \"forced update\" in the output is strange because I'm using `git push` and not `git push --force-with-lease`.\n\nAm I still missing a configuration setting that I should be aware of? I'm not getting errors but the output is odd.\n\n\n> On Aug 6, 2023, at 7:07 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> \n> Brooke Kuhlmann <brooke@alchemists.io> writes:\n> \n>> ... o why default branch push behavior is being\n>> ignored/overwritten.\n> \n> The root of your confusion lies around here, I think.  The \"default\"\n> branch push behaviour is given only when you do not customize.  Once\n> you add customization, you would specify _exactly_ what you want.\n> \n> In other words, the customization is NOT something you tell Git to\n> do _in addition to_ what it does anyway (otherwise you would not be\n> able to configure _away_ what is usually done by default when you do\n> not want to see it done).\n> \n\n"},{"id":"480216","messageId":"xmqq4jlaj0dp.fsf@gitster.g","threadId":"60071","inReplyTo":"2301E39E-B70D-485B-AFA8-F8DA64B366A2@alchemists.io","subject":"Re: Git Commit Notes (fetching/pushing)","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-08-07T16:14:10Z","receivedAt":"2023-08-07T16:14:21Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Brooke Kuhlmann <brooke@alchemists.io> writes:\n\n> I ended up using the following configuration in order to\n> explicitly fetch/push branches, notes, and tags:\n>\n> [remote \"origin\"]\n> \turl = https://github.com/bkuhlmann/test\n> \tfetch = +refs/heads/*:refs/remotes/origin/*\n> \tfetch = +refs/notes/*:refs/notes/*\n> \tfetch = +refs/tags/*:refs/tags/*\n> \tpush = +refs/heads/*:refs/remotes/origin/*\n\nThis will push your local branches (e.g. refs/heads/xyzzy) to their\nremote-tracking branches (e.g. refs/remotes/origin/xyzzy) of the\nsame name.  Is that what you meant?  It is unclear what kind of use\nyou have your remote repository for, and in some use cases, it is\nperfectly valid if a push from here is used as a substitute for a\nfetch from there to arrange the push from here like how you have\nabove, to push into refs/remotes/origin/* of a remote repository\nwith a working tree.\n\nBut often, a remote is used as a publishing point (i.e. everybody\npulls from and only you push into it) or as a central meeting place\n(i.e. everybody pulls from and pushes into it), and in these cases,\na push refspec would look more like\n\n\tpush = refs/heads/*:refs/heads/*\n\nThis is especially true when the remote is a bare repository, or\nhosted at a hosting site you or nobody has access to its working\ntree.\n\nNote the lack of leading '+'; that is absolutely essential if you\nare pushing into a central meeting place because you want to avoid\nforce pushing that will clobber others' work, and it is also a great\ndiscipline even if you are pushing into your publishing point\nbecause those in your downstream will be disrupted if you rewind\nyour history.\n\n\n"},{"id":"480253","messageId":"4230982C-7401-4EC0-907A-85E04074237D@alchemists.io","threadId":"60071","inReplyTo":"xmqq4jlaj0dp.fsf@gitster.g","subject":"Re: Git Commit Notes (fetching/pushing)","fromName":"Brooke Kuhlmann","fromEmail":"brooke@alchemists.io","sentAt":"2023-08-07T20:18:33Z","receivedAt":"2023-08-07T20:18:51Z","isPatch":false,"sender":{"key":"brooke@alchemists.io","avatar":"https://gravatar.com/avatar/4bd27d52fe87760d2bde1d384f0139eb81013709a0cf27ce654d48a7852727fa?d=mp&s=160"},"body":"Hy Junio, thanks.\n\nA few important lessons learned here (in case it helps others):\n\n1. Use `push = refs/heads/*:refs/heads/*` when pushing (this is what made everything work for me). Especially since my host is GitHub in this situation and I don't have control to the remote working tree as you point out.\n2. Don't use the `+` prefix for fetches and pushes as you point out. I didn't realize the value of this prefix until now, especially since this seems to be default behavior when cloning a repository so I was mostly following the default syntax.\n\nHere's my working configuration based on your feedback:\n\n[remote \"origin\"]\n  url = https://github.com/bkuhlmann/test\n  fetch = +refs/heads/*:refs/remotes/origin/*\n  fetch = refs/notes/*:refs/notes/*\n  fetch = refs/tags/*:refs/tags/*\n  push = refs/heads/*:refs/heads/*\n  push = refs/notes/*:refs/notes/*\n  push = refs/tags/*:refs/tags/*\n\nI'm a heavy rebaser (only on feature branches, never `main`) so definitely don't wish to clobber work accidentally even when using `git push --force-with-lease` or the `push.useForceIfIncludes = true` configuration setting.\n\nOne interesting side-effect that I've noticed with all of these changes is that my `branch.autoSetupRebase = always` configuration no longer knows how to automatically setup tracking for new feature branches when using `git switch --create <example>`. Even using the `-t` flag doesn't quite work either. I'll need to tinker with this some more.\n\nOtherwise, all of this appears to be working nicely as I can push/pull to my repository and then clone the same repository at a different location on disk and see all of my branches and notes sync appear properly.\n\nThanks again, this has been great to learn!\n\n> On Aug 7, 2023, at 10:14 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> \n> Brooke Kuhlmann <brooke@alchemists.io> writes:\n> \n>> I ended up using the following configuration in order to\n>> explicitly fetch/push branches, notes, and tags:\n>> \n>> [remote \"origin\"]\n>> url = https://github.com/bkuhlmann/test\n>> fetch = +refs/heads/*:refs/remotes/origin/*\n>> fetch = +refs/notes/*:refs/notes/*\n>> fetch = +refs/tags/*:refs/tags/*\n>> push = +refs/heads/*:refs/remotes/origin/*\n> \n> This will push your local branches (e.g. refs/heads/xyzzy) to their\n> remote-tracking branches (e.g. refs/remotes/origin/xyzzy) of the\n> same name.  Is that what you meant?  It is unclear what kind of use\n> you have your remote repository for, and in some use cases, it is\n> perfectly valid if a push from here is used as a substitute for a\n> fetch from there to arrange the push from here like how you have\n> above, to push into refs/remotes/origin/* of a remote repository\n> with a working tree.\n> \n> But often, a remote is used as a publishing point (i.e. everybody\n> pulls from and only you push into it) or as a central meeting place\n> (i.e. everybody pulls from and pushes into it), and in these cases,\n> a push refspec would look more like\n> \n> push = refs/heads/*:refs/heads/*\n> \n> This is especially true when the remote is a bare repository, or\n> hosted at a hosting site you or nobody has access to its working\n> tree.\n> \n> Note the lack of leading '+'; that is absolutely essential if you\n> are pushing into a central meeting place because you want to avoid\n> force pushing that will clobber others' work, and it is also a great\n> discipline even if you are pushing into your publishing point\n> because those in your downstream will be disrupted if you rewind\n> your history.\n> \n> \n\n"}]}