我如何分叉一个公共存储库,但使我的分叉私有?我确实订阅了支持私有存储库。
当前回答
2021年更新
我是git的新手,所以想在eclipse GUI中做尽可能多的事情(v2020-12;EGit v5.11)。下面的细节。
其他答案中的导入方法仅为Subversion、Mercurial或TFS项目设计。GitHub不支持git项目,这是我亲身体验到的。这可能有用,但为什么要冒险呢?
存储库和GitHub连接
eclipse / org。Aspectj是原始的公共repo,也是用于获取的上游远程 cb4 / org。Aspectj是用于推送的fork和源远程 cb4/remPrivAJ是远程私有回购和用于推送的私有远程 I:\local是本地回购
对于github身份验证,我使用了带有ed25519密钥的ssh(在这个SO答案中的步骤),因此我的连接uri看起来像这样:ssh://git@github.com/<user>/<repo>。
->是鼠标点击或选择;右->是一个右击。
步骤
在github上,将原始的公共回购叉到你的github帐户 在github上,创建空的远程私有回购 在eclipse Git透视图中,将fork克隆到一个新的本地回购并配置它
3.1-> Clone a Git Repository and add clone to this view -> Clone URI -> Next 3.1.1 Enter the URI, Connection, and Authentication info as appropriate -> Next 3.1.2. Select desired branches (I selected only master) -> Next 3.1.3. Enter destination directory for local repo 3.1.4. Import projects now or do it later, then -> Finish to populate the local repo 3.2. Configure the original public repo as a new remote named upstream for pulling down updates 3.2.1. right-> Remotes -> Create Remote -> and enter name upstream 3.2.2. -> Configure fetch -> Create -> Change -> enter original repo URI -> Finish 3.2.3. -> Save and Fetch -> all branches are downloaded -> Close 3.2.4. NOTE: I only wanted the master branch, so did this instead of Step 3.2.3 3.2.5. -> Advanced under Specifications to fetch, delete the lone entry there 3.2.6. Under Add create/update specification -> Source ref: dropdown and select master [branch] -> +Add Spec -> Force Update 3.2.7. -> Save specifications in upstream configuration -> Finish -> Save and Fetch -> only master branch is downloaded -> Close
将远程公共回购复制到远程私有回购并进行配置。这是唯一不能在eclipse中完成的步骤,所以我安装了Git for Windows并使用GitCMD。
像这样:
git clone --bare git://github.com/eclipse/org.aspectj.git tmpRepo
<if prompted, enter ssh passphrase>
cd tmpRepo
git push --mirror ssh://git@github.com:cb4/private.git
<if prompted, enter ssh passphrase>
cd ..
rmdir tmpRepo /s /q
将远程私有回购配置为一个名为private的用于推送的新远程
5.1. right-> Remotes ->创建Remote ->,并输入name private 5.2. ->配置推送->创建->更改->输入远端私有回购URI ->完成 5.3. —>高级—>添加所有分支规格—>强制更新—>保存原始配置规格—>完成 5.4. ->推送保存主分支->关闭
至此,您已经将一个公共回购分叉到您的私有存储库中。要了解如何将私有更改推到您的fork,然后打开一个针对原始公共回购的拉请求,请参阅我的回答。最终的配置如下所示:
其他回答
现在多了一个选择(2015年1月)
创建一个新的私有回购 在空的回购屏幕上有一个“导入”选项/按钮 点击它,并把现有的github回购url 没有github选项提到,但它与github回购工作太。 完成
答案是正确的,但没有提到如何在公共回购和分叉之间同步代码。
以下是完整的工作流程(我们在开源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上有文档:复制一个存储库
2021年更新
我是git的新手,所以想在eclipse GUI中做尽可能多的事情(v2020-12;EGit v5.11)。下面的细节。
其他答案中的导入方法仅为Subversion、Mercurial或TFS项目设计。GitHub不支持git项目,这是我亲身体验到的。这可能有用,但为什么要冒险呢?
存储库和GitHub连接
eclipse / org。Aspectj是原始的公共repo,也是用于获取的上游远程 cb4 / org。Aspectj是用于推送的fork和源远程 cb4/remPrivAJ是远程私有回购和用于推送的私有远程 I:\local是本地回购
对于github身份验证,我使用了带有ed25519密钥的ssh(在这个SO答案中的步骤),因此我的连接uri看起来像这样:ssh://git@github.com/<user>/<repo>。
->是鼠标点击或选择;右->是一个右击。
步骤
在github上,将原始的公共回购叉到你的github帐户 在github上,创建空的远程私有回购 在eclipse Git透视图中,将fork克隆到一个新的本地回购并配置它
3.1-> Clone a Git Repository and add clone to this view -> Clone URI -> Next 3.1.1 Enter the URI, Connection, and Authentication info as appropriate -> Next 3.1.2. Select desired branches (I selected only master) -> Next 3.1.3. Enter destination directory for local repo 3.1.4. Import projects now or do it later, then -> Finish to populate the local repo 3.2. Configure the original public repo as a new remote named upstream for pulling down updates 3.2.1. right-> Remotes -> Create Remote -> and enter name upstream 3.2.2. -> Configure fetch -> Create -> Change -> enter original repo URI -> Finish 3.2.3. -> Save and Fetch -> all branches are downloaded -> Close 3.2.4. NOTE: I only wanted the master branch, so did this instead of Step 3.2.3 3.2.5. -> Advanced under Specifications to fetch, delete the lone entry there 3.2.6. Under Add create/update specification -> Source ref: dropdown and select master [branch] -> +Add Spec -> Force Update 3.2.7. -> Save specifications in upstream configuration -> Finish -> Save and Fetch -> only master branch is downloaded -> Close
将远程公共回购复制到远程私有回购并进行配置。这是唯一不能在eclipse中完成的步骤,所以我安装了Git for Windows并使用GitCMD。
像这样:
git clone --bare git://github.com/eclipse/org.aspectj.git tmpRepo
<if prompted, enter ssh passphrase>
cd tmpRepo
git push --mirror ssh://git@github.com:cb4/private.git
<if prompted, enter ssh passphrase>
cd ..
rmdir tmpRepo /s /q
将远程私有回购配置为一个名为private的用于推送的新远程
5.1. right-> Remotes ->创建Remote ->,并输入name private 5.2. ->配置推送->创建->更改->输入远端私有回购URI ->完成 5.3. —>高级—>添加所有分支规格—>强制更新—>保存原始配置规格—>完成 5.4. ->推送保存主分支->关闭
至此,您已经将一个公共回购分叉到您的私有存储库中。要了解如何将私有更改推到您的fork,然后打开一个针对原始公共回购的拉请求,请参阅我的回答。最终的配置如下所示:
GitHub现在有一个导入选项,可以让你选择任何你想要的新导入的公共或私有存储库
推荐文章
- 如何运行一个github-actions步骤,即使前一步失败,同时仍然失败的工作
- 当我试图推到原点时,为什么Git告诉我“没有这样的远程‘原点’”?
- 在GitHub repo上显示Jenkins构建的当前状态
- 如何从远程分支中挑选?
- 如何查看一个分支中的哪些提交不在另一个分支中?
- 如何取消在github上的拉请求?
- HEAD和master的区别
- GIT克隆在windows中跨本地文件系统回购
- RPC失败;卷度传输已关闭,剩余未完成的读取数据
- 我应该在.gitignore文件中添加Django迁移文件吗?
- 错误:您对以下文件的本地更改将被签出覆盖
- Git rebase—即使所有合并冲突都已解决,仍然会继续报错
- 在Git中,我如何知道我的当前版本是什么?
- 跟踪所有远程git分支作为本地分支
- 自定义SSH端口上的Git