GitHub - 如何将存储库克隆到多个存储库并将每个存储库推送到GitHub

时间:2016-02-22 00:03:16

标签: git github

我的任务是将GitHub上的repository克隆到本地的多个存储库。

所有存储库应与克隆的旧存储库具有相同的代码库。然后,我将能够对每个存储库进行代码更改,并将每个存储库推送到GitHub上的单个存储库。

App 1

App 2

App 3

我能够将旧存储库克隆到如上所述推送到GitHub上的多个存储库。但是如何更新每个克隆的存储库以及对旧存储库所做的更改?

2 个答案:

答案 0 :(得分:1)

你的问题有点令人困惑。正如评论所说,听起来你想要分支机构,而不是存储库,如果这一切都是为了你自己。如果您尝试分叉代码并且需要使用不同的存储库,则任何推/拉操作的默认远程都是origin。默认情况下,origin指向从中克隆的远程,但没有什么特别之处,可以使用git remote命令进行更改。

例如:

git clone https://github.com/ParsePlatform/parse-server-example parse-server-example1
cd parse-server-example1
git remote rm origin
git remote add origin https://github.com/ParsePlatform/parse-server-example1
(repeat for 2 and 3)

会实现你所要求的。如果已经有不同的分叉,你可以使用其他名称制作遥控器,并在“git push”中明确指出要推送的远程/分支。

例如:

cd parse-server-example1
git remote add example2 https://github.com/ParsePlatform/parse-server-example2
git push example2 master
(repeat for as many different repos/names as you want, ie.)
git remote add example1 https://github.com/ParsePlatform/parse-server-example1

将你的(本地)example1代码推送到example2 fork和(在上面之后)

git fetch example2
git checkout example2/master
(do stuff, maybe commit)
git checkout example1/master

将在本地切换不同的叉子。这通常是一种更好的工作方式,除非您有理由需要同时将多个副本克隆到不同的目录中。

答案 1 :(得分:0)

感谢driusan的回答,我想我对这个问题的回答是: 将上游repo:OLD_REPO_URL克隆到GitHub上我自己帐户的新存储库中:

https://github.com/{MY_ACCOUNT}/parse-server-example-APP1
https://github.com/{MY_ACCOUNT}/parse-server-example-APP2
https://github.com/{MY_ACCOUNT}/parse-server-example-APP3

通过以下命令:

git clone https://github.com/ParsePlatform/parse-server-example parse-server-example-APP1
cd parse-server-example-APP1
git remote rm origin
git remote add origin https://github.com/{MY_ACCOUNT}/parse-server-example-APP1
(repeat for 2 and 3)

现在已经创建了新的存储库,我可以处理每个存储库并对代码进行更改。完成后将代码更改回原点。

如果OLD_REPO已更新,请运行以下命令以使用克隆的repos获取和合并更新:

cd parse-server-example-APP1
git remote add upstream https://github.com/ParsePlatform/parse-server-example
git fetch upstream
git merge upstream/master
git push