How do I push to a pull request on github?

GitGithubPull Request

Git Problem Overview


I've added this to my .git/config file:

fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

Which allows me to pull down pull request diffs, but when I check it out it actually creates a branch with that same name. Is there any way for me to push to pr/2 and have it actually go to the pull request instead of going to a new branch named pr/2?

Git Solutions


Solution 1 - Git

Here's are GitHub's "Merging via command line" instructions for pull requests (I am fulldecent, the other guy is ospr):

Step 1: From your project repository, check out a new branch and test the changes.

git checkout -b ospr-image-rendering master
git pull https://github.com/ospr/FDWaveformView.git image-rendering

Step 2: Merge the changes and update on GitHub.

git checkout master
git merge --no-ff ospr-image-rendering
git push origin master

Here is the additional step that sends your changes back upstream(?) to the PR originator.

git push https://github.com/ospr/FDWaveformView.git ospr-image-rendering:image-rendering

Solution 2 - Git

A Pull Request is just a request to merge a certain branch. This means commits made to the branch after the pull request is opened will be included in the eventual merge.

If you have access to the branch that the pull request is asking to merge, you can commit to that branch and the pull request will update with the changes.

Example:

pull/3 is requesting to merge hotfix into master

git fetch
git checkout hotfix
git pull origin hotfix

make changes

git add .
git commit -m "changes!"
git push origin hotfix

Now your commit will show up in the pull request.

Solution 3 - Git

Good question. But I would be surprised if you could:

$ cat .git/refs/pull/upstream/839 
f8a9f492098e154b4a8258a941af47c9ca017ada

Even if you can somehow change that reference to what you like, github has other metadata that you can't easily change. So better push to the branch pull was created from.

$ git push git@github.com:owner/repo.git HEAD:target-branch

See the github command line wrapper for easier github interaction from command line: https://hub.github.com/

In summary: You can push to an existing pull request if you push to the fork/branch that PR is based on. It is often possible depending on repo settings.

git push git@github.com:username/repo-name.git localbranchname:remotebranchname

or if you have the fork added as a remote in your local repo, then:

git push remotename localbranchname:remotebranchname

Solution 4 - Git

The GitHub Desktop client will create another pull request (PR) that includes the original PR and your changes if you try to merge changes to a PR you checked out.

I did this off of my master branch but presumably you could make another branch and then create a pull request to the pull request. It's all magical to me though with these fancy Git GUIs.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionlobatiView Question on Stackoverflow
Solution 1 - GitWilliam EntrikenView Answer on Stackoverflow
Solution 2 - GitRossView Answer on Stackoverflow
Solution 3 - GitakostadinovView Answer on Stackoverflow
Solution 4 - Gitcarlin.scottView Answer on Stackoverflow