简体   繁体   English

同步连接到两个远程服务器的两个本地git仓库

[英]Sync two local git repos connected to two remote servers

My situation is this: 我的情况是这样的:

I have a remote server, remote1 from which I've cloned a git repo onto my PC, local1. 我有一台远程服务器remote1,从中我已将一个git repo克隆到我的PC本地1中。

I have a second remote server, remote2 from which I've cloned a git repo onto my PC, local2. 我还有第二台远程服务器remote2,从中我已将git repo复制到我的PC本地2中。

NB These are both supposed to be the same project as remote1 is going to be decommissioned and replaced with remote2. 注意:这些都应该是与remote1将要退役并由remote2替换的项目。

I physically copied over the files from local1 into local2. 我将文件从local1物理复制到local2。 Just the cp command without any git commands. 只是cp命令,没有任何git命令。

Then I did a git add on local2 and git commit and git push on local2. 然后我在local2上执行了git add并在local2上执行了git commit和git push。

Now remote2 is a clone of remote1 as are local1 and local2 现在remote2和remote1和local2一样是remote1的克隆

I work in a corporate env and I'm coming back to this work after a few weeks. 我在一家公司的环境中工作,几周后我将重新从事这项工作。 Remote1 has move ahead with a few new branches and commits. Remote1已经有了一些新的分支和提交。 No problem. 没问题。 I do a git pull on local1 and it's up to date. 我对local1执行git pull,它是最新的。 Now I want to propagate the same changes from local1 to local2. 现在,我想将相同的更改从local1传播到local2。 Now the cp isn't as useful as it'll lose branches/history info. 现在,cp不再有用,它会丢失分支/历史记录信息。 How do I get local2 synced up with loca11? 如何使local2与loca11同步? Once local2 is synced up with local1 (same as remote1) I'd like to push to remote2. 将local2与local1(与remote1相同)同步后,我想推送到remote2。 In the meantime, there have been no changes on remote2 or local2. 同时,remote2或local2上没有任何更改。

End goal: remote1, local1, local2, remote2 are all in sync and are the exact same and reflect the current state of remote1. 最终目标:remote1,local1,local2,remote2都是同步的,并且完全相同,并反映了remote1的当前状态。

The move from local1 to local2 is what I need help with. 从local1到local2的迁移是我需要的帮助。

Thanks -SM 谢谢-SM

After thinking about your requirement, I believe what you need is Git fork . 考虑了您的需求之后,我相信您需要的是Git fork

Fork is used to clone (make copy of) existing repository on cloud source code management systems like github/bitbucket to another cloud source code management system. Fork用于将github / bitbucket之类的云源代码管理系统上的现有存储库克隆(复制)到另一个云源代码管理系统。 In simllp terms, for cloning repositories to and from cloud/remote. 用simllp术语来说,用于将存储库与云/远程克隆。 It will copy all the branch history along with the files. 它将复制所有分支历史记录以及文件。

After forking your repo at new remote, you can always pull the changes to the local copy of that repo. 在新的远程服务器上分叉存储库之后,您始终可以将更改拉到该存储库的本地副本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM