我在 github 上有一个公共存储库,我组的每个用户都有一个它的分支。该政策是禁止直接提交到主存储库,所有更改都必须作为来自分叉的拉取请求进来,以便在合并到主存储库之前可以对其进行审查。
鉴于有时我们开发的代码必须在主存储库中公开之前保持私有一段时间,我希望出现以下情况:
- 主要回购公开
- 福克斯私人
- 能够从分支向主存储库发出拉取请求
- 考虑到一些用户是 git 初学者,让事情变得简单
现在,在 Github 上这是不可能的,因为不允许私人分叉。
我可以使用什么策略来实现类似的行为?
我刚刚做了类似的事情。
对我有用的解决方案是创建一个新的私有存储库作为主存储库的裸克隆,并将所有新更改推送到此私有存储库,一旦更改准备好公开,将更改推送到公共回购。
我按照以下步骤操作:回答这个问题:Martin Konicek https://stackoverflow.com/questions/10065526/github-how-to-make-a-fork-of-public-repository-private/30352360#30352360
-
复制存储库(详细信息here https://help.github.com/articles/duplicating-a-repository/):
-
创建一个新的存储库(private-repo
)通过GitHub用户界面 https://github.com/new. Then:
git 克隆 --barehttps://github.com/exampleuser/public-repo.git https://github.com/exampleuser/public-repo.gitcd 公共仓库.git
git push --镜像https://github.com/yourname/private-repo.git https://github.com/yourname/private-repo.git光盘 ..
rm -rf 公共仓库.git
-
克隆私人存储库,以便您可以对其进行处理:
克隆https://github.com/yourname/private-repo.git https://github.com/yourname/private-repo.gitcd 私人回购
做一些改变
git 提交
git推送原点大师
-
要从公共存储库中提取新的更改:
cd 私人回购
git 远程添加公共https://github.com/exampleuser/public-repo.git https://github.com/exampleuser/public-repo.gitgit pull public master # 创建合并提交
git推送原点大师
私人存储库现在拥有公共存储库中的最新代码以及您的更改。
- 创建拉取请求私有存储库 -> 公共存储库:
创建拉取请求需要推送对公共存储库的访问权限,因为您需要推送到那里的分支(这就是为什么 https://stackoverflow.com/questions/14821583/pull-request-without-forking).
git clone https://github.com/exampleuser/public-repo.git
cd public-repo
git remote add private_repo https://github.com/yourname/private-repo.git
git checkout -b pull_request_branch
git pull private_repo master
git push origin pull_request_branch
现在只需通过 Github UI 为 public-repo 创建一个拉取请求,如所述here https://help.github.com/articles/creating-a-pull-request/.
一旦项目审查了拉取请求,您就可以合并它。
第一次之后,您只需从所需的远程(公共或私有)中拉取并推送到(私有)即可。完成更改后,将更改推送到(私有:以保持最新)和公共上的某个分支,以便可以创建对 master 的拉取请求。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)