如何使两个git回购相同

如何使两个git回购相同,git,gitlab,Git,Gitlab,我在两个独立的gitlab部署上有两个代码相同的git Repo。它不是gitlab EE,因此我没有镜像功能 起初,我确保每次承诺都会被推到两个回购协议上,但随着时间的推移,它失去了控制,我可以公正地对待这种做法 目前,我强烈希望使repo1与repo2相同。但在这样做的时候,我似乎陷入了一个圈子 我就是这么做的: $ git pull repo1 master ...there are conflicts. ...I resolve them, add the file, then do

我在两个独立的gitlab部署上有两个代码相同的git Repo。它不是gitlab EE,因此我没有镜像功能

起初,我确保每次承诺都会被推到两个回购协议上,但随着时间的推移,它失去了控制,我可以公正地对待这种做法

目前,我强烈希望使
repo1
repo2
相同。但在这样做的时候,我似乎陷入了一个圈子

我就是这么做的:

$ git pull repo1 master
...there are conflicts. 
...I resolve them, add the file, then do git rebase --continue
$ git push repo1 master --now this works
$ git pull repo2 master
...there are conflicts. 
...I resolve them, add the file, then do git rebase --continue
$ git push repo2 master
经过以上,我会想象一切都很好。但是现在,当我执行
git pull repo1 master
时,我必须重新执行上述步骤

问题

除了从gitlab中删除repo1并重新开始之外,是否有其他方法可以强制使
repo1
repo2
相同


此外,展望未来,保持两次回购同步的最佳方式是什么?

是否真的有必要让这两次回购完全相等? 如果是,则只从本地推送到repo1,然后从repo1推送到repo2会更容易(例如,使用git post接收挂钩)

但是现在您可以尝试
强制推送
git push-f)覆盖repo1中的提交历史记录。(假设repo2包含“正确”的历史记录,repo1包含错误的历史记录):

从报告1:

git remote add repo2 <path to the other repo>
git checkout master
git fetch repo2
git reset --hard repo2/master
git远程添加repo2
切换到主分支
git获取报告2
git复位——硬复位2/主
对您感兴趣的每个分支都这样做(可能只是master和development分支?)

git remote add repo2 <path to the other repo>
git checkout master
git fetch repo2
git reset --hard repo2/master