如何 fork 公共(public)存储库,但将我的 fork 设为私有(private)?我确实订阅了支持私有(private)存储库的订阅。
最佳答案
答案是正确的,但没有提到如何在公共(public)仓库和 fork 之间同步代码。
这是完整的工作流程(我们在开源 React Native 之前已经这样做了):
首先,复制其他人所说的repo(详细信息 here ):
通过 Github UI 创建一个新的存储库(我们称之为 private-repo
)。然后:
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
克隆私有(private)存储库,以便您可以对其进行处理:
git clone https://github.com/yourname/private-repo.git
cd private-repo
make some changes
git commit
git push origin master
从公共(public)仓库中提取新的热点:
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
太棒了,您的私有(private)仓库现在拥有来自公共(public)仓库的最新代码以及您的更改。
最后,创建一个 pull 请求私有(private)仓库 -> 公共(public)仓库:
使用 GitHub UI 创建公共(public)存储库的 fork (公共(public)存储库页面右上角的小“ 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 为 public-repo 创建 pull 请求,如 here 所述。
一旦项目所有者审查您的 pull 请求,他们就可以 merge 它。
当然,整个过程可以重复(只需省略添加 Remote 的步骤)。
关于GitHub:如何将公共(public)存储库的分支设为私有(private)?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10065526/