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

Re: How to mirror and augment a git repository

From
STSebastian Tennant <sdt@sebyte.me>
Date
Mar 12, 2023, 18:11 UTC
Message-ID
<87pm9d6drp.fsf@sebyte.me>
In-Reply-To
<ZAyWUS27M+degQxj@coredump.intra.peff.net>

Quoth Jeff King <peff@peff.net> on Sat, 11 Mar 2023 09:55:13 -0500:

Show 17 quoted lines
> On Sat, Mar 11, 2023 at 10:47:40AM +0000, Sebastian Tennant wrote:
>
>> Here are the actions I'm taking to configure the mirror:
>>
>>  $ git clone --bare https://url.of/project.git
>>  $ cd project.git
>>  $ git remote rename origin upstream
>>  $ git config remote.upstream.fetch\
>>        '+refs/heads/*:refs/remotes/upstream/*'
>>  $ git fetch upstream --prune
>>
>> At this point there are no refs under refs/heads (and very many under
>> refs/remotes/upstream).
>
> You'd have refs under refs/heads at this point.  They were created
> when you did the original bare clone (since bare clones fetch all
> heads to start with, though they don't set up a refspec).
I see the refs under refs/heads at last!

My mistake was looking for them in the file system (instead of in file ‘packed-refs’).

Show 11 quoted lines
> And they won't be deleted by the pruning fetch, of course, because
> you configured the refspec to limit itself to refs/remotes/upstream
> on the local side.
>
> If you don't want them (and I think you don't), you can just initialize
> the repository directly, and then fetch, like:
>
>   git init --bare project.git
>   cd project.git
>   git config remote.upstream.url https://url.of/project.git
>   [and then configure refspec and fetch --prune as before]

This is precisely the behaviour I've been wanting (and mistakenly expecting).

Show 26 quoted lines
>> Here are the actions I'm then taking on a client:
>>
>>  $ git clone --bare mirror:path/to/project.git
>>  $ cd project.git
>>  $ git remote rename origin mirror
>>  $ git config remote.mirror.fetch\
>>        '+refs/heads/*:refs/remotes/mirror/*'
>
> This bare clone will do the same thing. So you'll end up with a copy
> of all of the heads created in the earlier step. Worse, they won't
> be the current state of those branches, but stale ones left from
> when you created the mirror repo.
>
> I think you want _two_ refspecs in the clients:
>
>   - one to fetch the client-local branches stored on the mirror. That
>     is:
>
>       +refs/heads/*:refs/remotes/origin/*
>
>     and those branches just appear as normal.
>
>   - one to fetch the mirrored upstream branches from the special
>     namespace on the mirror. That one is:
>
>       +refs/remotes/upstream/*:refs/remotes/upstream/*

Yup, this is what I want, and actually what I already have in place, configuration wise.

The problem was in my partial understanding of the consequences of passing option --bare to ‘git clone’ (and in my not thinking to look in file ‘packed-refs’).

Thanks again Jeff.
Sebastian
Previous: Jeff KingNext: Jeff King
Message 9 of 10 in “How to mirror and augment a git repository”
  1. Sebastian TennantMar 4, 2023
  2. Bagas SanjayaMar 5, 2023
  3. Sebastian TennantMar 5, 2023
  4. Jeff KingMar 6, 2023
  5. Sebastian TennantMar 8, 2023
  6. Jeff KingMar 9, 2023
  7. Sebastian TennantMar 11, 2023
  8. Jeff KingMar 11, 2023
  9. Sebastian TennantMar 12, 2023
  10. Jeff KingMar 13, 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.