48

My project on GitHub has received a pull request. The pull request only partly fixes the issue that it's addressing. I've pulled in the changes to a local branch and added some commits of my own.

I'd now like to push those commits back to my remote repo and have them show up on the pull request, but without merging them into the target branch. I'd like to keep the pull request open for further review and discussion, and potentially further commits.

Is there a way I can add commits to the pull request without merging them into the target branch and therefore closing the pull request?

Platinum Azure
  • 45,269
  • 12
  • 110
  • 134
John Blackbourn
  • 791
  • 1
  • 8
  • 14
  • @PlatinumAzure Haha, wow, I have no idea how I swapped links. I meant this question. http://stackoverflow.com/questions/7947322/preferred-github-workflow-for-updating-a-pull-request-after-code-review?rq=1 – Chris Hayes Jan 05 '14 at 03:15
  • Thanks for the link Chris but that question is from the perspective of the pull request submitter, not the receiver. It seems that Henry Blyth's answer below is correct - it's currently not possible to do what I want. – John Blackbourn Jan 05 '14 at 03:49
  • possible duplicate of [What's a good way to merge in Github pull requests and possibly making changes to them first?](http://stackoverflow.com/questions/6474942/whats-a-good-way-to-merge-in-github-pull-requests-and-possibly-making-changes-t) – random Jan 05 '14 at 04:51

4 Answers4

56

As long as the original author has clicked the checkbox in the bottom right:

Allow Maintainers

If that box is checked, then you can push back to the original branch without needing to add a remote by using:

git push git@github.com:user/repo local_branch_name:remote_branch_name

This is particularly useful if you're using a tool like hub where you can check out a pull request without needing to add a remote.

Edit: You also need to have write access to the repository where the PR has been opened.

Further Edit: The new command line tool from GitHub does a good job of checking out PRs so that you can just use git push as is to push updates to remotes (assuming you have permission).

Wesley Bland
  • 8,816
  • 3
  • 44
  • 59
  • Do you know if the command you wrote is somehow easier to do with hub? My best workflow thus far has been to first `hub pr checkout ###`, then make changes, and then use your listed command. – Kyle Holmberg Oct 12 '19 at 08:27
  • AFAIK, there isn't a hub command to do this. I've not been using `hub` nearly as much lately though so it's possible that it could have been added. – Wesley Bland Oct 22 '19 at 18:37
  • Is this possible even if I am not the original author of the repository on which the PR has been sent? I receive an ERROR message: "Permission to user/repository.git denied to myself" – Saverio Guzzo Sep 15 '21 at 13:49
  • Two things have to be true: 1) The original author must have checked that box, and 2) you must have write access to the repository that the PR is made against. – Wesley Bland Sep 15 '21 at 17:10
36

It is possible to do this now (link)

Suppose you have received a pull request in yourrepo from otheruser.

Add the other user as a remote

git remote add otheruser https://github.com/otheruser/yourrepo.git

Fetch

git fetch otheruser

Create a branch from their repo

git checkout -b otheruser-master otheruser/master 

Now make some changes and commit. Push to their repo

git push otheruser HEAD:master
Mendhak
  • 8,194
  • 5
  • 47
  • 64
7

Not unless barryceelen gives you push access to his fork. You'll have to close his pull request and open a new one from your branch that includes his commits.

Not being able to do what you want to do is annoying. To make better use of GitHub flow, I'd suggest asking forkers to open issues separately from their pull requests that solve them, meaning you can keep the initial conversation flow and have it closed by whatever pull request you decide as the best.

Henry Blyth
  • 1,700
  • 1
  • 15
  • 23
0

I use the new gh cli tool.

gh pr checkout PR_NUMBER

Then make your changes and as long as you have access to push to their fork (which from my experience is usually the case if you own the primary repo). With using the gh tool, it will basically copy their branch's name so you can do.

git push git@github.com:other_user/repo branch:branch
Alex Cory
  • 10,635
  • 10
  • 52
  • 62