32

Here's the scenario:

I have a public repo A. Bob forks A, adds a few commits to Bob/master and submits a pull request to merge those changes in A/master. I'd like to make a few changes to the proposed pull request before merging it back to A/master.

How can I do that if I can't push to Bob/master?

Javier Soto
  • 4,840
  • 4
  • 26
  • 46

3 Answers3

19

There are a number of workflows you can use here. Some examples are:

  1. Comment on the pull request, and have Bob make some changes. See Pull Request Discussion for more info.

  2. Merge the pull request onto a different branch, then make your changes before merging to master. You need to do this from the command line; see Merging a Pull Request for step-by-step instructions.

  3. Edit the patch before applying it with git am. See Patch and Apply. This is probably the most flexible option, but also the most manual.

    git checkout master
    curl http://github.com/<username>/<project_name>/pull/<patch_number>.patch
    sensible-editor <patchfile>
    git am <patchfile>
    git push origin master
    
mlissner
  • 17,359
  • 18
  • 106
  • 169
Todd A. Jacobs
  • 81,402
  • 15
  • 141
  • 199
  • No ideal, but works, I specially like option 1. With option 3, I would take credit for Bob's commits, right? – Javier Soto Jun 16 '12 at 19:55
  • Follow-on question moved here: http://stackoverflow.com/questions/11066980/who-gets-credit-for-a-hand-edited-patch-file – Todd A. Jacobs Jun 16 '12 at 21:00
  • For more involved changes, there's no need to edit the patch by hand. After applying the patch with `git am` you can edit the repo files directly and then commit them with the `--amend` flag. – Pete Mar 20 '13 at 03:45
  • How do you (the repository owner) update the pull request with changes so the original author (of the pull request) can review the changes before you merge them with master? – Jon Mar 20 '16 at 09:25
2

You can just pull from his branch on your local repo (not inside the github gui)

# make same work-in-progress branch and check it out
$ git checkout -b WIP

# pull his changes into WIP
$ git pull https://github.com/... master

and then mercilessly change from there on.

The other option would be to use github's comment system to talk him into changing his patchset (that way he could also keep the credit after the merge).

Benjamin Bannier
  • 55,163
  • 11
  • 60
  • 80
  • 7
    Isn't there any way that we both can keep credit? a way so that his and my commits appear listed under the pull request... – Javier Soto Jun 16 '12 at 19:34
  • 1
    If you make commits and then merge his commits, don't all commits get preserved from a credit perspective? – gregturn Jan 10 '14 at 02:58
  • @gregturn: If you change a commit the author gets changed, but does stay the original value if you just cherry-pick a commit. – Benjamin Bannier Jan 10 '14 at 09:08
2

One solution is to make a PR into Bob/master containing your revisions. Bob can merge your PR into Bob/master; when you merge Bob's PR into A/master, it will contain Bob's commits and your commits.

You can create a PR from any fork/branch to any other fork/branch. So if Bob submits a PR from Bob/feature, just create a PR into Bob/feature.

Jeff-Meadows
  • 2,154
  • 18
  • 25