How to modify a pull request on GitHub to change target branch to merge into?

GitGithub

Git Problem Overview


I have a pull request that is requesting a merge into master from my branch, but the owner wants me to change the request to merge into a different branch from my branch.

Is this possible? What are the possible solutions?

Git Solutions


Solution 1 - Git

Update August 2016: Change the base branch of a Pull Request finally allows for changing that branch.
(And this closes issue 18, which was 3 years old and had 1500+ comments)

> 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.

enter image description here

As noted in the comments byspazm:

> It is (and was) working.
> > Changing target branch is not enabled while the PR is closed.
Solution was to "reopen" the PR (meaning by using the option in the UI) and then change the target branch


Original answer:

Since a PR cannot be edited in term of branch (see below), the easiest way would be to:

  • create a local new branch on top of your current branch
  • push that new branch
  • make a new PR with the right destination.
  • close the previous PR
  • reference the "old" pull request from the new one; eg. Supersedes #123 (as commented below by Rivera)

(original answer, valid only when creating the PR)

You could try and chose another base branch, as in "Changing the branch range and destination repository" (Clicking on the Edit button at the top of a PR page)

https://github-images.s3.amazonaws.com/help/pull_requests/pull-request-review-edit-branch.png

> The easiest way of thinking about the branch range is this: > > - the base branch is where you think changes should be applied, >- the head branch is what you would like to be applied. > > Changing the base repository changes who is notified of the pull request.
Everyone that can push to the base repository will receive an email notification and see the new pull request in their dashboard the next time they sign in.

If you select as a base branch the one that the original maintainer (the owner) wants, your PR should merge from your branch (unchanged) to the new base branch.

Solution 2 - Git

If your branch is (still) available remotely, you do not have to create a new branch locally.

  • Select your branch (which bears the changes you are submitting) either directly from the drop-down menu or under "# branches" (https://github.com/account/project/branches).

  • Click "New pull request". This lets you choose a new base (target) branch.

Here is a screenshot of Github's new interface: enter image description here

I can submit a PR of branch UX against any fork/branch---it doesn't matter whether I previously submitted a PR for branch UX.

Solution 3 - Git

You can now: https://github.com/blog/2224-change-the-base-branch-of-a-pull-request

"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."

Solution 4 - Git

You have to create a new pull request as mentioned in the GibHub documentationForm

  1. First select New Pull request
  2. in the compare page, left side select the target branch you want to push and right side select the branch you already pushed.
  3. Update the details for your new PR.
  4. Create the PR

Solution 5 - Git

It's pretty simple. Just click the PR for which you want to change its base branch. Find "Close pull request" button near the bottom of the web page. Now you can recreate a new PR normally - make sure you select the correct base branch this time.

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
QuestionMoriartyView Question on Stackoverflow
Solution 1 - GitVonCView Answer on Stackoverflow
Solution 2 - GitmkcorView Answer on Stackoverflow
Solution 3 - GitMK.View Answer on Stackoverflow
Solution 4 - GitAni ThettayilView Answer on Stackoverflow
Solution 5 - GitGolden ThumbView Answer on Stackoverflow