【问题标题】:Pushing a commit to branch of another user who has opened a pull request将提交推送到已打开拉取请求的另一个用户的分支
【发布时间】:2017-07-22 15:02:29
【问题描述】:

我在 github 上有一个存储库。我的存储库是由另一个用户分叉的。现在他提出了一个拉取请求。我想将我的一个提交推送到他的功能分支(他为此提出了 PR)。这可能吗。

这就是我所做的

git pull remote-ref-other-user feature-branch

完成此操作后,我可以提取他的提交。但是当我进行一些更改时,添加另一个提交并尝试以这种方式推送它。

git push remote-ref-other-user feature-branch

我收到此错误

error: src refspec feature-branch does not match any.
error: failed to push some refs to 'https://github.com/other-user/repo'

是否可以将我这边的提交推送到他的分支。如果是,那怎么做。

【问题讨论】:

  • 您可以随时向分叉的 repo 发出 counter PR。

标签: git github push commit git-branch


【解决方案1】:

假设您添加他的存储库,例如“mysamplerepository”,作为远程​​:

git remote add johnrepo https://github.com/john/mysamplerepository

你的分支叫tweaks

如果您想将更改推送到他的存储库中名为 master 的分支,您可以这样做:

git push <remote-name> <source-ref>:<target-ref>

或者在这个例子中:

git push johnrepo refs/heads/tweaks:refs/heads/master

请记住,您还需要具有写入权限(推送访问权限)才能推送到他的存储库。您可以在 Github's documentation 上阅读更多相关信息。

【讨论】:

  • 感谢@kopranb 成功了。 git push <remote-name> <source-ref>:<target-ref> 这个命令对我有用。 +1
【解决方案2】:

如果可能,将取决于写入权限:

  • 作为存储库所有者,您应该拥有向其他用户的 PR 添加提交的写入权限(除非在用户的 PR 中明确关闭此功能)
  • 如果您不是存储库所有者,您将无法向其他用户的 PR 添加额外的提交

为GitHub用户添加远程后,例如

git remote add <name of remote> git@github.com:<user>/<repo>.git

我用

git checkout -b <name of branch> <name of remote>/<name of branch> 

创建一个本地分支跟踪远程。在我做出更改并提交后,我可以这样做:

git push <name of remote> <name of branch>

【讨论】:

    猜你喜欢
    • 2010-10-27
    • 2012-12-03
    • 1970-01-01
    • 1970-01-01
    • 2020-02-12
    • 2018-12-19
    • 2013-05-03
    • 2022-01-22
    相关资源
    最近更新 更多