Merge pull request to a different branch than default, in Github
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!
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.
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:
- Add a remote for the fork to your local checkout.
- Fetch that remote.
git checkout ${target_branch} && git merge ${remote}/${branch}
git push origin ...
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.