Pushing a commit to branch of another user who has opened a pull request

人走茶凉 提交于 2019-12-24 02:16:23

问题


I have a repository on github. My repository is forked by another user. Now he has raised a pull request. I would like to push one commit from my end to his feature branch(for which he has raised a PR). Is this possible.

Here is what I did

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

After doing this I am able to pull his commits. but when I do some change, add another commit and try to push it this way.

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

I get this error

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

Is it possible to push a commit from my side to his branch. If yes then how can it be done.


回答1:


Say you add his repository, say "mysamplerepository", as a remote:

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

And you have your branch called tweaks.

If you want to push your changes to a branch called master in his repository, you would do:

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

or in this example:

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

Remember that you also need to have write permission (push access) to push to his repository. You can read more about this on Github's documentation.




回答2:


If this is possible, will depend on write permissions:

  • as repository owner, you should have write permission to add commits to PR of another user (unless this was explicitly turned off in the PR of the user)
  • if you are not repository owner, you will not be able to add additional commits to PR of another user

After adding the remote for the GitHub user, e.g.

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

I use

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

to create a local branch tracking the remote. After I made changes and committed, I can do:

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


来源:https://stackoverflow.com/questions/42563008/pushing-a-commit-to-branch-of-another-user-who-has-opened-a-pull-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!