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

Re: Keeping a non-1:1 mirror in sync and keeping private branches

From
Jeff King <peff@peff.net>
Date
Jul 16, 2017, 14:16 UTC
Message-ID
<20170716141637.bsdkj4i5rncd7h5m@sigill.intra.peff.net>
In-Reply-To
<eb5e02da-662e-5561-7548-e50efba13dca@gmail.com>
On Sun, Jul 16, 2017 at 03:42:09PM +0200, Jan Danielsson wrote:
Show 11 quoted lines
> >   1. Drop the pruning (in which case deleted branches from the sync may
> >      accumulate, but depending on the patterns that may or may not be a
> >      problem).
> 
>    I don't think that's a problem.  Or rather, I'd be willing to try it
> and see if it becomes a problem.
> 
>    That said; does "drop the pruning" mean simply removing "--prune"
> from the remove update?  I did that, but it still deletes my test-branch
> on push.  Is there an implicit pruning happening due to some
> configuration option or the specific commands I'm using?

No, that prune is fetching from your upstream into the bridge repo. So it is dropping refs from the bridge that went away upstream. My assumption is that your "private" branches are not in the bridge, but just in the $DOWNSTREAMURL.

The issue is in the "git push" after that. Your "git remote add --mirror=push" set up config like this:

  [remote "origin"]
  url = ...
  mirror = true
and the "mirror" there implies the prune. Instead, you'd want to do:
  git config remote.origin.url $DOWNSTREAMURL
  git config remote.origin.push "+refs/*:refs/*"

Note that the "+" means a force-push. If you do have personal branches in the downstream, their contents may be overwritten by the sync from upstream. You can drop the "+", but then if upstream ever rewinds a branch, your sync would fail.

Show 7 quoted lines
> >   2. Use two different namespaces for the synced branches and the
> >      private ones (e.g., refs/mirror/* in addition to your branches in
> >      refs/heads/*). The obvious downside is that anybody cloning your
> >      downstream mirror doesn't pick up refs/mirror unless they configure
> >      that refspec explicitly.
>    This sounds very useful.  How would one go about setting up this
> configuration?

I'm not 100% clear on where your private branches are. Are they in the bridge repo, too, or only in the eventual downstream? I'll assume they're only in the downstream, and that the bridge is purely a tool for syncing.

In that case, you might do:
  git clone --mirror -o upstream $UPSTREAM bridge.git
  cd bridge.git
  git config remote.downstream.url $DOWNSTREAM
  git config remote.downstream.push "+refs/*:refs/mirror/*"
  git config remote.downstream.prune true

Though I'm not 100% sure that the "prune" config is respected for pushes. You might have to skip that last config and just issue:

  git push --prune downstream

If you're scripting it, I'd actually consider doing the whole thing without config at all:

  # do this once
  git init bridge.git
  cd bridge.git
  # and put this in your sync script
  git fetch --prune $UPSTREAM +refs/*:refs/*
  git push --prune $DOWNSTREAM +refs/*:refs/mirror/*
-Peff
Previous: Jan Danielsson
Message 4 of 4 in “Keeping a non-1:1 mirror in sync and keeping private branches”
  1. Jan DanielssonJul 16, 2017
  2. Jeff KingJul 16, 2017
  3. Jan DanielssonJul 16, 2017
  4. Jeff KingJul 16, 2017

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.