How do I synchronise two remote Git repositories?

后端 未结 6 922
北荒
北荒 2020-12-24 08:40

I have two repository urls, and I want to synchronise them such that they both contain the same thing. In Mercurial, what I\'m trying to do would be:

hg pull         


        
6条回答
  •  忘掉有多难
    2020-12-24 09:02

    You might not have seen that the fetch did in fact work when you used git clone --mirror --bare, because by default git does not list it's remote branches. You can list them with git branch -a.

    I don't quite have the syntax worked out for unnamed remotes, but you could automatically add remotes based on some scheme from the url... in any case, it'll probably work best if you choose some unique and consistent name for each repo, so you can know what changes came from where

    However, you could try something like this:

    git clone --bare --mirror --origin thing1 {repo1} repo.git
    cd repo.git
    git fetch thing2 --mirror
    git push thing1 --mirror
    git push thing2 --mirror
    

    After this was done, thing1 would have all of thing2's branches available to merge at any time, as remote branches. You can list the remote branches with git branch -a.

    On github or bitbucket, you will not be able to see these remote branches via the web interfaces, however you can see them if you clone with --mirror, so they do exist.

提交回复
热议问题