git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Git Commit Notes (fetching/pushing)
@ 2023-08-06 18:35 Brooke Kuhlmann
  2023-08-06 20:09 ` Taylor Blau
  0 siblings, 1 reply; 7+ messages in thread
From: Brooke Kuhlmann @ 2023-08-06 18:35 UTC (permalink / raw)
  To: git

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

Here's my configuration:

```
[notes]
  rewriteRef = refs/notes/commits

[remote "origin"]
  fetch = +refs/notes/*:refs/notes/*
  push = +refs/notes/*:refs/notes/*
```

Upon creating a note (i.e. `git notes add`) and then pushing changes to the remote, I'll see the following response from GitHub:

``` 
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 289 bytes | 289.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/bkuhlmann/test
   5811bd44c32b..0f2422597c5d  refs/notes/commits -> refs/notes/commits
```

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

Anyway, if anyone has advice or additional information how this should work (or if my configuration is wrong), I'd be grateful. 🙇🏻‍♂️





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Git Commit Notes (fetching/pushing)
  2023-08-06 18:35 Git Commit Notes (fetching/pushing) Brooke Kuhlmann
@ 2023-08-06 20:09 ` Taylor Blau
  2023-08-06 21:49   ` Brooke Kuhlmann
  0 siblings, 1 reply; 7+ messages in thread
From: Taylor Blau @ 2023-08-06 20:09 UTC (permalink / raw)
  To: Brooke Kuhlmann; +Cc: git

On Sun, Aug 06, 2023 at 12:35:50PM -0600, Brooke Kuhlmann wrote:
> 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)?
>
> Here's my configuration:
>
> ```
> [notes]
>   rewriteRef = refs/notes/commits
>
> [remote "origin"]
>   fetch = +refs/notes/*:refs/notes/*
>   push = +refs/notes/*:refs/notes/*
> ```

It looks like your refspec may not be doing what you think it is.

Here, you set both the default fetch and push refspecs to
"+refs/notes/*:refs/notes/*" which means to update anything under
the "refs/notes" hierarchy on either side, even when the updates are not
fast forwards.

Since you overwrote the default refspec, you end up only pushing the
notes, which we see from the response that you got back from GitHub:

> remote: Resolving deltas: 100% (1/1), completed with 1 local object.
> To https://github.com/bkuhlmann/test
>    5811bd44c32b..0f2422597c5d  refs/notes/commits -> refs/notes/commits

Indeed, refs/notes/commits is updated on your bkuhlmann/test repository,
which I can fetch from:

    $ git remote add origin git@github.com:bkuhlmann/test.git
    $ git fetch origin 'refs/notes/*:refs/notes/*'
    remote: Enumerating objects: 41, done.
    remote: Counting objects: 100% (41/41), done.
    remote: Compressing objects: 100% (29/29), done.
    remote: Total 41 (delta 14), reused 34 (delta 7), pack-reused 0
    Unpacking objects: 100% (41/41), 4.66 KiB | 1.55 MiB/s, done.
    From github.com:bkuhlmann/test
     * [new ref]           refs/notes/commits -> refs/notes/commits

I suspect you want an additional refspec that gathers any branches or
tags that you want to push along with refs/notes/*.

Thanks,
Taylor

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Git Commit Notes (fetching/pushing)
  2023-08-06 20:09 ` Taylor Blau
@ 2023-08-06 21:49   ` Brooke Kuhlmann
  2023-08-07  1:07     ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Brooke Kuhlmann @ 2023-08-06 21:49 UTC (permalink / raw)
  To: Taylor Blau; +Cc: git

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.

Originally, 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?

Here's my complete local configuration in case it helps:

[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = https://github.com/bkuhlmann/test
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
remote = origin
merge = refs/heads/main
rebase = true

I was hoping to update the remote "origin" as:

[remote "origin"]
url = https://github.com/bkuhlmann/test
fetch = +refs/heads/*:refs/remotes/origin/*
        fetch = +refs/notes/*:refs/notes/*
        push = +refs/notes/*:refs/notes/*

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

> On Aug 6, 2023, at 2:09 PM, Taylor Blau <me@ttaylorr.com> wrote:
> 
> On Sun, Aug 06, 2023 at 12:35:50PM -0600, Brooke Kuhlmann wrote:
>> 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)?
>> 
>> Here's my configuration:
>> 
>> ```
>> [notes]
>>  rewriteRef = refs/notes/commits
>> 
>> [remote "origin"]
>>  fetch = +refs/notes/*:refs/notes/*
>>  push = +refs/notes/*:refs/notes/*
>> ```
> 
> It looks like your refspec may not be doing what you think it is.
> 
> Here, you set both the default fetch and push refspecs to
> "+refs/notes/*:refs/notes/*" which means to update anything under
> the "refs/notes" hierarchy on either side, even when the updates are not
> fast forwards.
> 
> Since you overwrote the default refspec, you end up only pushing the
> notes, which we see from the response that you got back from GitHub:
> 
>> remote: Resolving deltas: 100% (1/1), completed with 1 local object.
>> To https://github.com/bkuhlmann/test
>>   5811bd44c32b..0f2422597c5d  refs/notes/commits -> refs/notes/commits
> 
> Indeed, refs/notes/commits is updated on your bkuhlmann/test repository,
> which I can fetch from:
> 
>    $ git remote add origin git@github.com:bkuhlmann/test.git
>    $ git fetch origin 'refs/notes/*:refs/notes/*'
>    remote: Enumerating objects: 41, done.
>    remote: Counting objects: 100% (41/41), done.
>    remote: Compressing objects: 100% (29/29), done.
>    remote: Total 41 (delta 14), reused 34 (delta 7), pack-reused 0
>    Unpacking objects: 100% (41/41), 4.66 KiB | 1.55 MiB/s, done.
>    From github.com:bkuhlmann/test
>     * [new ref]           refs/notes/commits -> refs/notes/commits
> 
> I suspect you want an additional refspec that gathers any branches or
> tags that you want to push along with refs/notes/*.
> 
> Thanks,
> Taylor



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Git Commit Notes (fetching/pushing)
  2023-08-06 21:49   ` Brooke Kuhlmann
@ 2023-08-07  1:07     ` Junio C Hamano
  2023-08-07 14:02       ` Brooke Kuhlmann
  0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2023-08-07  1:07 UTC (permalink / raw)
  To: Brooke Kuhlmann; +Cc: Taylor Blau, git

Brooke Kuhlmann <brooke@alchemists.io> writes:

> ... o why default branch push behavior is being
> ignored/overwritten.

The root of your confusion lies around here, I think.  The "default"
branch push behaviour is given only when you do not customize.  Once
you add customization, you would specify _exactly_ what you want.

In other words, the customization is NOT something you tell Git to
do _in addition to_ what it does anyway (otherwise you would not be
able to configure _away_ what is usually done by default when you do
not want to see it done).


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Git Commit Notes (fetching/pushing)
  2023-08-07  1:07     ` Junio C Hamano
@ 2023-08-07 14:02       ` Brooke Kuhlmann
  2023-08-07 16:14         ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Brooke Kuhlmann @ 2023-08-07 14:02 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Taylor Blau, git

Thanks Junio. Yep, I see where I went wrong now and learned something new in the process.

I ended up using the following configuration in order to explicitly fetch/push branches, notes, and tags:

[remote "origin"]
	url = https://github.com/bkuhlmann/test
	fetch = +refs/heads/*:refs/remotes/origin/*
	fetch = +refs/notes/*:refs/notes/*
	fetch = +refs/tags/*:refs/tags/*
	push = +refs/heads/*:refs/remotes/origin/*
	push = +refs/notes/*:refs/notes/*
	push = +refs/tags/*:refs/tags/*

The 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:

To https://github.com/bkuhlmann/test
   709004099276..1eefe6a1101c  refs/notes/commits -> refs/notes/commits
 + a966604d7864...e0a75df6084f release -> origin/release (forced update)

Seeing "forced update" in the output is strange because I'm using `git push` and not `git push --force-with-lease`.

Am I still missing a configuration setting that I should be aware of? I'm not getting errors but the output is odd.


> On Aug 6, 2023, at 7:07 PM, Junio C Hamano <gitster@pobox.com> wrote:
> 
> Brooke Kuhlmann <brooke@alchemists.io> writes:
> 
>> ... o why default branch push behavior is being
>> ignored/overwritten.
> 
> The root of your confusion lies around here, I think.  The "default"
> branch push behaviour is given only when you do not customize.  Once
> you add customization, you would specify _exactly_ what you want.
> 
> In other words, the customization is NOT something you tell Git to
> do _in addition to_ what it does anyway (otherwise you would not be
> able to configure _away_ what is usually done by default when you do
> not want to see it done).
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Git Commit Notes (fetching/pushing)
  2023-08-07 14:02       ` Brooke Kuhlmann
@ 2023-08-07 16:14         ` Junio C Hamano
  2023-08-07 20:18           ` Brooke Kuhlmann
  0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2023-08-07 16:14 UTC (permalink / raw)
  To: Brooke Kuhlmann; +Cc: Taylor Blau, git

Brooke Kuhlmann <brooke@alchemists.io> writes:

> I ended up using the following configuration in order to
> explicitly fetch/push branches, notes, and tags:
>
> [remote "origin"]
> 	url = https://github.com/bkuhlmann/test
> 	fetch = +refs/heads/*:refs/remotes/origin/*
> 	fetch = +refs/notes/*:refs/notes/*
> 	fetch = +refs/tags/*:refs/tags/*
> 	push = +refs/heads/*:refs/remotes/origin/*

This will push your local branches (e.g. refs/heads/xyzzy) to their
remote-tracking branches (e.g. refs/remotes/origin/xyzzy) of the
same name.  Is that what you meant?  It is unclear what kind of use
you have your remote repository for, and in some use cases, it is
perfectly valid if a push from here is used as a substitute for a
fetch from there to arrange the push from here like how you have
above, to push into refs/remotes/origin/* of a remote repository
with a working tree.

But often, a remote is used as a publishing point (i.e. everybody
pulls from and only you push into it) or as a central meeting place
(i.e. everybody pulls from and pushes into it), and in these cases,
a push refspec would look more like

	push = refs/heads/*:refs/heads/*

This is especially true when the remote is a bare repository, or
hosted at a hosting site you or nobody has access to its working
tree.

Note the lack of leading '+'; that is absolutely essential if you
are pushing into a central meeting place because you want to avoid
force pushing that will clobber others' work, and it is also a great
discipline even if you are pushing into your publishing point
because those in your downstream will be disrupted if you rewind
your history.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Git Commit Notes (fetching/pushing)
  2023-08-07 16:14         ` Junio C Hamano
@ 2023-08-07 20:18           ` Brooke Kuhlmann
  0 siblings, 0 replies; 7+ messages in thread
From: Brooke Kuhlmann @ 2023-08-07 20:18 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Taylor Blau, git

Hy Junio, thanks.

A few important lessons learned here (in case it helps others):

1. 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.
2. 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.

Here's my working configuration based on your feedback:

[remote "origin"]
  url = https://github.com/bkuhlmann/test
  fetch = +refs/heads/*:refs/remotes/origin/*
  fetch = refs/notes/*:refs/notes/*
  fetch = refs/tags/*:refs/tags/*
  push = refs/heads/*:refs/heads/*
  push = refs/notes/*:refs/notes/*
  push = refs/tags/*:refs/tags/*

I'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.

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

Otherwise, 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.

Thanks again, this has been great to learn!

> On Aug 7, 2023, at 10:14 AM, Junio C Hamano <gitster@pobox.com> wrote:
> 
> Brooke Kuhlmann <brooke@alchemists.io> writes:
> 
>> I ended up using the following configuration in order to
>> explicitly fetch/push branches, notes, and tags:
>> 
>> [remote "origin"]
>> url = https://github.com/bkuhlmann/test
>> fetch = +refs/heads/*:refs/remotes/origin/*
>> fetch = +refs/notes/*:refs/notes/*
>> fetch = +refs/tags/*:refs/tags/*
>> push = +refs/heads/*:refs/remotes/origin/*
> 
> This will push your local branches (e.g. refs/heads/xyzzy) to their
> remote-tracking branches (e.g. refs/remotes/origin/xyzzy) of the
> same name.  Is that what you meant?  It is unclear what kind of use
> you have your remote repository for, and in some use cases, it is
> perfectly valid if a push from here is used as a substitute for a
> fetch from there to arrange the push from here like how you have
> above, to push into refs/remotes/origin/* of a remote repository
> with a working tree.
> 
> But often, a remote is used as a publishing point (i.e. everybody
> pulls from and only you push into it) or as a central meeting place
> (i.e. everybody pulls from and pushes into it), and in these cases,
> a push refspec would look more like
> 
> push = refs/heads/*:refs/heads/*
> 
> This is especially true when the remote is a bare repository, or
> hosted at a hosting site you or nobody has access to its working
> tree.
> 
> Note the lack of leading '+'; that is absolutely essential if you
> are pushing into a central meeting place because you want to avoid
> force pushing that will clobber others' work, and it is also a great
> discipline even if you are pushing into your publishing point
> because those in your downstream will be disrupted if you rewind
> your history.
> 
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-08-07 20:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-06 18:35 Git Commit Notes (fetching/pushing) Brooke Kuhlmann
2023-08-06 20:09 ` Taylor Blau
2023-08-06 21:49   ` Brooke Kuhlmann
2023-08-07  1:07     ` Junio C Hamano
2023-08-07 14:02       ` Brooke Kuhlmann
2023-08-07 16:14         ` Junio C Hamano
2023-08-07 20:18           ` Brooke Kuhlmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).