git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Git Commit Notes (fetching/pushing)

From
Brooke Kuhlmann <brooke@alchemists.io>
Date
Aug 7, 2023, 20:18 UTC
Message-ID
<4230982C-7401-4EC0-907A-85E04074237D@alchemists.io>
In-Reply-To
<xmqq4jlaj0dp.fsf@gitster.g>
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!
Show 42 quoted lines
> 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.
> 
> 
Previous: Junio C Hamano
Message 7 of 7 in “Git Commit Notes (fetching/pushing)”
  1. Brooke KuhlmannAug 6, 2023
  2. Taylor BlauAug 6, 2023
  3. Brooke KuhlmannAug 6, 2023
  4. Junio C HamanoAug 7, 2023
  5. Brooke KuhlmannAug 7, 2023
  6. Junio C HamanoAug 7, 2023
  7. Brooke KuhlmannAug 7, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.