GitHub 可以从私有仓库拉取请求到公共仓库吗?

发布于 2024-12-26 06:30:27 字数 282 浏览 1 评论 0原文

我分叉了一个公共存储库并将新的存储库设为私有。

我在我的私人存储库上添加了一个新的远程分支,并提交了一些修复。

现在,我想从我的私人存储库中的分支向我分叉的公共存储库创建拉取请求。

我在我的私人存储库中选择分支并单击“拉取请求”。

我点击“更改提交”。

我无法更改组织/存储库所有者。我只看到我的组织,但看不到公共仓库的组织。我只能针对我的私人存储库的主分支创建拉取请求,但这不是我想要的。

是否无法在私人仓库中修复公共仓库的某些内容并随后创建拉取请求?

I forked a public repo and made the new repo private.

I added a new remote branch on my private repo with some fixes committed.

Now, I want to create a pull request from the branch in my private repo towards the public repo I forked from.

I select the branch in my private repo and click "Pull request".

I click on "Change commits".

I can't change the organisation/repo owner. I only see my organisation, but not the one of the public repo. I could only create a pull request against master branch of my private repo, but that's not what I want.

Is it not possible to fix something of a public repo in a private one and create a pull request afterwards?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我很坚强 2025-01-02 06:30:27

一种解决方案是将原始公共存储库分叉到您自己的 GitHub 上公共存储库中。
然后 将您分叉的公共存储库复制到私有存储库中一个

然后,您将两者克隆到本地工作站上,并且:

  • 在您的私有本地存储库上进行公共和私有修改,
  • 首先将私有修改推送到您的本地公共存储库,
  • 然后将它们推送到您的 GitHub 分叉公共存储库
  • 从 GitHub 上的分叉公共存储库发出拉取请求。

One solution would be to fork the original public repo into your own public repo on GitHub.
Then duplicate your forked public repo into a private one.

You then clone both on your local workstation, and:

  • do public and private modifications on your private local repo
  • push private modifications first to your local public repo
  • then push them to your GitHub forked public repo
  • make your pull request from your forked public repo on GitHub.
梦幻的心爱 2025-01-02 06:30:27

2021 更新

@VonC 的答案在概念上是正确的,并且仍然是 GitHub 支持的答案。九年后,@Sebi终于得到了他想要的答案 - 我消除了他评论的 VonC 答案第二个项目符号中出现的“间接”。

对于我的用例,我需要对公共存储库进行公共私有更改。公共提交一旦准备好就可以定期推送。私人更改必须保留在我的私人存储库中,直到我完成我的博士研究。那时,我需要所有私人更改通过拉取请求从我的公共分叉流到原始公共存储库。

大部分工作是正确设置。我在此答案中提供了详细步骤。以下步骤仅在 eclipse GUI(v2020-12;EGit 5.11)中完成,但可以轻松转换为命令行操作。我使用的存储库如下:

  • eclipse/org.aspectj原始公共存储库;用于获取cb4/org.aspectj上游远程
  • 是我的fork;用于推送cb4/remPrivAJorigin远程
  • 是我的远程私有存储库;用于推送和拉取的 private 远程
  • I:\local 是我工作站上的本地存储库

对于 github 身份验证,我使用 ssh 和 ed25519 ssh键(这个问题的操作方法) 所以我的连接 URI 如下所示: ssh://[电子邮件受保护]/<用户>/<存储库>

表示法: -> 是鼠标单击或选择; 右->double-> 分别是右键单击和双击。


我将公共更改与私人更改分开,将每个更改放在单独的分支中:pub 用于公共更改; priv 用于私人更改。我对 git 相当陌生,所以可能有更好的方法来做到这一点。

  1. 创建和配置分支
  • 1.1 在 eclipse Git Perspective 中,在本地存储库下:打开 Branches 然后打开 Local (每个旁边都有 -> v
  • 1.2 对于私有分支:右键->大师->创建分支->选择->私有/主控->确定 输入 priv 作为分支名称:->配置上游的推和拉 ->拉取时:合并->完成
  • 1.3 对于公共分支:右键->大师->创建分支 输入 pub 作为分支名称:->完成
  • 1.4 结果:在我的私人存储库 private/master、我的公共分叉 orign/master 和原始公共存储库 upstream/ 中提交编号掌握所有匹配
    config

  1. 进行私有更改并提交
  • 2.1 进行一些更改,然后在 Git 透视图的 Git Staging 选项卡上查看有关这些更改的详细信息
  • 2.2 选择各个更改并添加他们到单击绿色加号 2.3 来选择索引
  • ,或单击绿色双加号
  • 2.4 将其全部选择。输入提交消息和 ->;提交并推送 ->预览->推->关闭
  • 2.5 记下新的提交号
    commit

  1. 私有更改推送到公共分叉
  • right->;私人 ->推送分支->远程:下拉 v -> origin: URI (我的是 origin:ssh://[email protected] /cb4/org.aspectj) 双-> master 在 Branch: 文本框中输入 priv,然后输入 double->; priv [分支] ->预览->推->关闭

  1. 在 GitHub 上,我的公共分支中的私人更改。请注意此处与上面相同的提交号(单击图像进行缩放)。
    推送的更改

  1. 要完成该过程并针对原始公共存储库打开私有更改的拉取请求,只需单击“Compare &”即可。拉取请求 瞧! (点击图片可放大)。
    拉取请求

其他特性和功能

  • 当然,您可以将public提交推送到公共分叉:right->;酒吧->推送分支->预览->推->关闭
  • 尽可能频繁地从原始公共存储库中提取和合并更新,以减少合并冲突:在 Remotes 下 right->;上游->获取
  • 然后将它们推到您的叉子上:在“Remotes”下right->;起源->推送
  • 并到您的私人存储库:在远程右->;私人 ->推送

2021 Update

@VonC's answer is conceptually correct and still the one supported by GitHub. After nine years, @Sebi finally gets the answer he wanted -- I eliminated the "indirection" he commented on that occurs in the second bullet of VonC's answer.

For my use case, I need to make both public and private changes to a public repo. Public commits can be pushed periodically as soon as they are ready. Private changes must remain in my private repo until I complete my PhD research. At that time, I'll need all private changes to flow from my public fork to the original public repo via pull requests.

The bulk of the work is getting things set up correctly. I provided detailed steps in this SO answer. The following steps are done exclusively in the eclipse GUI (v2020-12; EGit 5.11), but can easily be translated to command line operations. The repositories I used are these:

  • eclipse/org.aspectj is the original public repo; the upstream remote for fetching
  • cb4/org.aspectj is my fork; the origin remote for pushing
  • cb4/remPrivAJ is my remote private repo; the private remote for pushing and pulling
  • I:\local is the local repo on my workstation

For github authentication, I used ssh with an ed25519 ssh key (how-to in this SO question) so my connection URIs look like this: ssh://[email protected]/<user>/<repo>.

Notation: -> is a mouse click or selection; right-> and double-> are right-click and double-click, respectively.


I separated public from private changes by putting each in separate branches: pub for public changes; priv for private changes. I'm fairly new to git, so there may be a better way to do this.

  1. Create and configure branches
  • 1.1 In the eclipse Git Perspective, under the local repo: open Branches then open Local (-> v beside each)
  • 1.2 For the private branch: right-> master -> Create Branch -> Select -> private/master -> Ok enter priv for Branch name: -> Configure upstream for push and pull -> When pulling: Merge -> Finish
  • 1.3 For the public branch: right-> master -> Create Branch enter pub for Branch name: -> Finish
  • 1.4 The result: commit numbers in my private repo private/master, my public fork orign/master, and the original public repo upstream/master all match
    config

  1. Make a private change and commit
  • 2.1 Make some changes, then see detailed info about them on the Git Staging tab in the Git Perspective
  • 2.2 Select individual changes and add them to the index by clicking the green plus sign
  • 2.3 OR select them all by clicking green double plus sign
  • 2.4. Enter a commit message and -> Commit and Push -> Preview -> Push -> Close
  • 2.5 Note the new commit number
    commit

  1. Push private changes to the public fork
  • right-> priv -> Push Branch -> Remote: dropdown v -> origin: URI (mine is origin:ssh://[email protected]/cb4/org.aspectj) double-> master in the Branch: text box and type priv then double-> priv [branch] -> Preview -> Push -> Close

  1. On GitHub, private changes in my public fork. Note same commit number here as above (click image to zoom).
    changes pushed

  1. To complete the process and open a pull request for a private change against the original public repo, just click on Compare & pull request and Voila! (click image to zoom).
    pull request

Additional Features and Functions

  • Of course, you can push public commits to the public fork: right-> pub -> Push Branch -> Preview -> Push -> Close
  • Pull and merge updates from the original public repo as frequently as it changes to reduce merge conflicts: under Remotes right-> upstream -> Fetch
  • Then push them to your fork: under Remotes right-> origin -> Push
  • And to your private repo: under Remotes right-> private -> Push
马蹄踏│碎落叶 2025-01-02 06:30:27

我怀疑这是 Github 的初衷,但实际上您可以通过一些简单的 DOM 操作从私有存储库向公共存储库发出拉取请求:

  1. 在私有存储库上进行更改,可能是在新分支上。
  2. 启动拉取请求。点击更改提交按钮。
  3. 打开一个允许您修改 DOM 的编辑器。像 Firebug 或 Safari Web 检查器或 Chrome 开发者工具这样的东西似乎工作得很好。
  4. 编辑基本分支存储库。您需要更改所选选项标签的值。
  5. 接下来,单击分支名称(如果需要,可以更改它)。您需要执行此操作才能触发 ajax 更新。
  6. 更新提交范围,你就可以开始了。

一些注意事项:

  • 对于公众或未列为协作者的用户,单击提交链接或查看文件将会出现 404 错误。合并后一切看起来都很好,但对于公共仓库的维护者来说可能有点奇怪。
  • 只需要从 UI 接受拉取请求。我不认为它会让任何人手动合并或挑选提交。冲突可能需要由私人回购所有者来解决。

I doubt it's intended by Github but you can actually make a pull request from a private to a public repo with a bit of simple DOM manipulation:

  1. Make your changes on your private repo, probably on a fresh branch.
  2. Start a pull request. Hit the change commits button.
  3. Open up an editor that allows you to modify the DOM. Things like Firebug or the Safari web inspector or Chrome developer tools seem to work fine.
  4. Edit the base branch repository. You'll want to change the selected option tag's value.
  5. Next, click on the branch name (and change it if you want). You need to do this to trigger an ajax update.
  6. Update the commit range and you should be good to go.

Some caveats:

  • Clicking the commit links or view file will 404 for the public or users who aren't listed as collaborators. Everything seems fine once it's merged in, but it may be a bit weird for the maintainer of the public repo.
  • The pull request needs to be accepted only from the UI. I don't think it'll let anyone merge or cherry-pick the commits in manually. Conflicts will likely need to be resolved by the private repo owner.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文