Can a project have multiple origins?
一个项目在Git中可以有两个(或更多)的"来源"?
我想把一个项目推到Github和Heroku服务器上。
具体来说,添加GitHub存储库时会出现此错误:
1 2  | $ git remote add origin https://github.com/Company_Name/repository_name.git fatal: remote origin already exists.  | 
您可以拥有任意多个遥控器,但只能有一个名为"原点"的遥控器。名为"origin"的远程程序在任何方面都不是特别的,只是它是在克隆现有存储库时由git创建的默认远程程序。您可以配置第二个遥控器,从该遥控器推/拉,并设置一些分支来跟踪来自该遥控器的分支,而不是原始分支。
尝试添加名为"github"的远程程序:
1 2 3 4 5 6 7 8 9 10  | $ git remote add github https://github.com/Company_Name/repository_name.git # push master to github $ git push github master # Push my-branch to github and set it to track github/my-branch $ git push -u github my-branch # Make some existing branch track github instead of origin $ git branch --set-upstream other-branch github/other-branch  | 
对于以后遇到此问题的任何人来说,一次可以将源站推送到多个Git存储库服务器,这是一个附带说明。
您可以通过使用以下命令将另一个URL添加到源站远程服务器来实现这一点。
1  | git remote set-url --add origin ssh://[email protected]/user/myproject.git  | 
号
下面是一个包含多个远程设备的示例项目,Github&Gitlab:
为GitHub添加远程回购
1  | $ git remote add github https://github.com/Company_Name/repository_name.git  | 
为Gitlab添加远程报告
1  | $ git remote add gitlab https://gitlab.com/Company_Name/repository_name.git  | 
。
现在项目中有多个遥控器。与
1 2 3 4 5  | $ git remote -v github https://github.com/Company_Name/repository_name.git (fetch) github https://github.com/Company_Name/repository_name.git (push) gitlab https://gitlab.com/Company_Name/repository_name.git (fetch) gitlab https://gitlab.com/Company_Name/repository_name.git (push)  | 
如何推送到多个存储库?
1  | $ git push github && git push gitlab  | 
。
您可以通过提供不同的名称(而不是源站)将另一个远程帐户添加到存储库中。您可以使用origin2等名称。所以您的git命令可以修改为
1  | git remote add origin2 https://github.com/Company_Name/repository_name.git  | 
。