我如何分叉一个公共存储库,但使我的分叉私有?我确实订阅了支持私有存储库。


当前回答

答案是正确的,但没有提到如何在公共回购和分叉之间同步代码。

以下是完整的工作流程(我们在开源React Native之前就已经这样做了):


首先,复制其他人所说的回购(详情在这里):

通过Github UI创建一个新的回购(让我们称之为私有回购)。然后:

git clone --bare https://github.com/exampleuser/public-repo.git
cd public-repo.git
git push --mirror https://github.com/yourname/private-repo.git
cd ..
rm -rf public-repo.git

克隆私有回购,这样你就可以对它进行操作:

git clone https://github.com/yourname/private-repo.git
cd private-repo
make some changes
git commit
git push origin master

从公共回购中获取新的热点:

cd private-repo
git remote add public https://github.com/exampleuser/public-repo.git
git pull public master # Creates a merge commit
git push origin master

太棒了,您的私人回购现在有来自公共回购的最新代码加上您的更改。


最后,创建一个pull request private repo -> public repo:

使用GitHub UI创建公共回购的fork(公共回购页面右上方的小“fork”按钮)。然后:

git clone https://github.com/yourname/the-fork.git
cd the-fork
git remote add private_repo_yourname https://github.com/yourname/private-repo.git
git checkout -b pull_request_yourname
git pull private_repo_yourname master
git push origin pull_request_yourname

现在,您可以通过Github UI为公共回购创建一个拉请求,如下所述。

一旦项目所有者审查了您的pull请求,他们就可以合并它。

当然,整个过程可以重复(只需省略添加遥控器的步骤)。

其他回答

GitHub现在有一个导入选项,可以让你选择任何你想要的新导入的公共或私有存储库

去https://github.com/new/import吧。

在“您的旧存储库的克隆URL”部分粘贴您想要的回购URL,并在“隐私”中选择“私有”。

答案是正确的,但没有提到如何在公共回购和分叉之间同步代码。

以下是完整的工作流程(我们在开源React Native之前就已经这样做了):


首先,复制其他人所说的回购(详情在这里):

通过Github UI创建一个新的回购(让我们称之为私有回购)。然后:

git clone --bare https://github.com/exampleuser/public-repo.git
cd public-repo.git
git push --mirror https://github.com/yourname/private-repo.git
cd ..
rm -rf public-repo.git

克隆私有回购,这样你就可以对它进行操作:

git clone https://github.com/yourname/private-repo.git
cd private-repo
make some changes
git commit
git push origin master

从公共回购中获取新的热点:

cd private-repo
git remote add public https://github.com/exampleuser/public-repo.git
git pull public master # Creates a merge commit
git push origin master

太棒了,您的私人回购现在有来自公共回购的最新代码加上您的更改。


最后,创建一个pull request private repo -> public repo:

使用GitHub UI创建公共回购的fork(公共回购页面右上方的小“fork”按钮)。然后:

git clone https://github.com/yourname/the-fork.git
cd the-fork
git remote add private_repo_yourname https://github.com/yourname/private-repo.git
git checkout -b pull_request_yourname
git pull private_repo_yourname master
git push origin pull_request_yourname

现在,您可以通过Github UI为公共回购创建一个拉请求,如下所述。

一旦项目所有者审查了您的pull请求,他们就可以合并它。

当然,整个过程可以重复(只需省略添加遥控器的步骤)。

现在多了一个选择(2015年1月)

创建一个新的私有回购 在空的回购屏幕上有一个“导入”选项/按钮 点击它,并把现有的github回购url 没有github选项提到,但它与github回购工作太。 完成

目前的答案有点过时了,所以,为了清楚起见:

简单的回答是:

做一个公共回购的纯克隆。 创建一个新的私有的。 做一个镜像推送到新的私有。

这在GitHub上有文档:复制一个存储库