A pull request comes into my repo hosted on Github. By default it is merged into the master
branch.
Is there any way for me to change which branch the changes would be merged into?
No, merging does only affect one branch.
As of 15.08.2016 GitHub allows changing the target branch of a pull request via the GUI. Click Edit
next to the title, then select the branch from the dropdown.
You can now change the base branch of an open pull request. After you’ve created a pull request, you can modify the base branch so that the changes in the pull request are compared against a different branch. By changing the base branch of your original pull request rather than opening a new one with the correct base branch, you’ll be able to keep valuable work and discussion.
The submitter can change that when they issue the pull request, but once they issue it you can't change it.
On the other hand, you can manually merge their branch and push, which I semi-regularly do for mistargetted pull requests.
You may find the hub
gem helpful in working with the components of the pull request.
That gem wraps up the manual process, which is:
git checkout ${target_branch} && git merge ${remote}/${branch}
git push origin ...
An alternative to using the hub gem mentioned by other answers is to use the command line to merge locally pull requests, which allows you to do:
$ git fetch origin
$ git checkout *target_branch*
$ git merge pr/XXX
$ git push origin *target_branch*
The commands above only work directly if you first add the following line to your .git/config
file:
fetch = +refs/pull/*/head:refs/remotes/symbolic_name_origin_or_upstream/pr/*
What that does is allow you to download ALL pull requests. Since that may not be desired for huge repos, GitHub modified the instructions to feature the git fetch origin pull/ID/head:BRANCHNAME
syntax, which avoids modification of the configuration file and only downloads that single pull request.
Although you cannot change the existing pull request as it is not yours, you can easily create a new one if the related source repository still exists - yes, even if it is someone else's.
Go to the repository of the submitter then create a new pull request in his/her repository using the same commits but make sure you set the right target branch correctly.
Then go back to your own repository and accept the new pull request. Voila!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With