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

Re: merge two local mirrors with detached heads and similar remotes

From
ZHZenaan Harkness <zen@freedbms.net>
Date
Nov 7, 2010, 09:27 UTC
Message-ID
<AANLkTi=JmpXEiEe-7-ZicUp-QosWjTZQgK77-f=9iAtL@mail.gmail.com>
In-Reply-To
<AANLkTinidbrJjmt5w=TyFGMyNpaGobE1iDBm3VAWmZvX@mail.gmail.com>
On Sun, Nov 7, 2010 at 13:40, Zenaan Harkness <zen@freedbms.net> wrote:
> I wish to merge two local mirrors, which each should share the same
> object store
...
Show 7 quoted lines
> So I want to achieve the same thing (multiple remotes in one local
> repo) for an earlier clone of two separate repos, which really ought
> to be just one, as follows:
>
> A)
> $ cd gitjour.git/
> $ cat .git/config
Show 6 quoted lines
> [remote "origin"]
>        fetch = +refs/heads/*:refs/remotes/origin/*
>        url = https://github.com/chad/gitjour.git
> [branch "master"]
>        remote = origin
>        merge = refs/heads/master
Show 8 quoted lines
> $ git branch -a
> * master
>  remotes/origin/HEAD -> origin/master
>  remotes/origin/master
>
> B)
> $ cd gitjour-new.git/
> $ cat .git/config
Show 13 quoted lines
> [remote "origin"]
>        fetch = +refs/heads/*:refs/remotes/origin/*
>        url = https://github.com/lachlanhardy/gitjour.git
> [branch "master"]
>        remote = origin
>        merge = refs/heads/master
> $ git branch -a
> * master
>  remotes/origin/8.2.0
>  remotes/origin/HEAD -> origin/master
>  remotes/origin/lachlanhardy
>  remotes/origin/master
>  remotes/origin/v8.1.0

It looks to me like I finally solved the first half of the problem, with clarification from the following URL: http://www.gelato.unsw.edu.au/archives/git/0601/15567.html

In A) I modified .git/config to be as follows:
$ cat .git/config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = https://github.com/chad/gitjour.git
[branch "master"]
        remote = origin
        merge = refs/heads/master
[remote "lach"]
        url = ../u
#       fetch = +refs/heads/*:refs/remotes/origin/*
        fetch = +refs/remotes/origin/*:refs/remotes/lach/*
$ git fetch lach d
remote: Counting objects: 583, done.
remote: Compressing objects: 100% (303/303), done.
remote: Total 568 (delta 229), reused 566 (delta 229)
Receiving objects: 100% (568/568), 65.29 KiB, done.
Resolving deltas: 100% (229/229), completed with 3 local objects.
From ../u
 * [new branch]      origin/8.2.0 -> lach/8.2.0
 * [new branch]      origin/HEAD -> lach/HEAD
 * [new branch]      origin/lachlanhardy -> lach/lachlanhardy
 * [new branch]      origin/v8.1.0 -> lach/v8.1.0
# and finally:
$ git branch -a
* master
  remotes/lach/8.2.0
  remotes/lach/HEAD
  remotes/lach/lachlanhardy
  remotes/lach/master
  remotes/lach/v8.1.0
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
---------
Looks very much like success to me. Small thing I notice is this line:
  remotes/origin/HEAD -> origin/master
has become this:
  remotes/lach/HEAD

(ie it's not a link any more - probably not particularly relevant, perhaps git gc would automate tidying this?) ---------- So now I just update the remote URL for lach to point back to upstream and I think I'm done. Happy days.

That tutorial email URL up top above might be old - http://www.gelato.unsw.edu.au/archives/git/0601/15567.html is from January 2006! - and is out of date a bit wrt the .git/config file format (eg remotes wildcards), BUT in that email, Junio explained this "local mirror" concept well enough that I could solve my problem here (it appears) - implementing a fixup of my "local mirror" use case - I'm a happy camper; thank you Junio!

May be I missed how to do this somewhere in the docs already, but I've been reading and searching the web for two days, learning lots for sure, but frustrated that it took me so long to find out how to do this.

Should something like Junio's tutorial go into Documentation/gitworkflows.xml(ARGGH!) ? If not, where else? Is there anything besides vim (about all I know) you can recommend for editing xml(ARGGH!) docs?

Thanks Zenaan

Previous: Zenaan HarknessNext: Zenaan Harkness
Message 2 of 4 in “merge two local mirrors with detached heads and similar remotes”
  1. Zenaan HarknessNov 7, 2010
  2. Zenaan HarknessNov 7, 2010
  3. Zenaan HarknessNov 7, 2010
  4. Jakub NarebskiNov 7, 2010

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.