How to open multiple pull requests on GitHub

GitGithubPull Request

Git Problem Overview


When I open a pull request on GitHub.
All commits since my last request and all new ones are automatically added to this request.

I can't seem to control which commits are added and which are not.
When I try to open another pull request, I get an "Oops! There's already a pull request" error.

Is there any easy way to open multiple pull requests without having to mess around with the command line?

Git Solutions


Solution 1 - Git

Pull requests are based on a branch.
The only way to open up a pull request for multiple commits is:

  1. Isolate them into their own branch.
  2. Open the pull requests from there.

Solution 2 - Git

The easiest way I've found to do this is with the hub command (https://github.com/defunkt/hub).

From your topic branch ("feature" in this example) that you want to create a pull request for, you can just run:

git pull-request

(remember to push your branch first!)

And it will open a new pull request on GitHub for "YOUR_USER:feature".

If you've already created an issue on GitHub, you can even attach a pull request to that existing issue (something you can't do from the web UI):

$ git pull-request -i 123
[ attached pull request to issue #123 ]

Solution 3 - Git

You can create Pull Request(PR), by making separate branches for your work.

Example:

  1. You checkout from a branch master into a branch work-1.

  2. You make some commits in branch work-1 as work-1-commit-1 and work-1-commit-2

  3. Now you create a PR from work-1 to master. Your code can be reviewed by seeing files changed from PR.

  4. Now, for further work you will checkout from branch work-1 into new branch work-2

  5. You make some commits in branch work-2 as work-2-commit-1 and work-2-commit-2

  6. Now you create a PR from work-2 to work-1. Your code can be reviewed by seeing files changed from PR.

Here the files changes will only have the new code you write after work-1-commit-2.

Solution 4 - Git

You actually CAN do this without creating another branch, but it takes a bit of playing around.
Here's the steps:

  1. Identify the two commit ranges you want to pull. Here's what i'll use for an example:
    (other/master) A -> B -> C -> D -> E (yours/master)
    Let's say that you want to pull B and C in one request, and D & E in another.
  2. Make a pull request. Have the left side ("Base") be commit A. For the right side ("head"), type in the commit number of C.
  3. Write the description for your first request.
  4. Make another request. For the base, type in the commit number of C, and for the head, put E (yours/master).
  5. Write the description.

As I see it, the pull request sees commit C as a branch point. Or something.

Solution 5 - Git

When you initially go to create the pull request, if you open two separate forms for a new pull request it will allow you to create them as long as they are pointed at different branches to be merged. For example, I could make two separate Requests, one to merge into master and another to merge into test.

Solution 6 - Git

I am new to Git and GitHub and had the same question as the OP.

I have found a solution, which probably was not available at the time of the OP.

Situation: You have 3 changes, and you want each to be built off the previous, and each to have their own pull request (PR).

Problem: When you create the first PR that tries to pull develop into master, every thing looks fine, but then after you make the changes for the second PR, and merge them (using the same branch) all the changes are in the same PR.

Mini Solution: Create a new branch

git branch mini_change_2
git checkout mini_change_2

Now you push the code to GitHub and create the PR, but it defaults to Pull from mini_change_2 to master, except master does not yet have the changes from the first PR, so it includes all the changes from PR1 and PR2.

Best Solution: Specify which branch you are merging to in PR2.

Do not just accept the defaults when creating the second PR, say you are going pulling mini_chnage_2 to Develop, this will only show the changes in mini_change_2

Now create a new branch mini_change_3 and PR that to mini_change_3.

The problem comes once you start merging them...but that is a different exercise.

Solution 7 - Git

Just found this one out today if you're not working across forks:

  1. Go to your branch in GitHub
  2. Click on the "Compare" button
  3. Change the base branch to compare against
  4. Click "Create Pull Request"
  5. ???
  6. PROFIT

Solution 8 - Git

If you go to the repository page, click on Pull Requests, there is a "New pull request" button which you can use to create pull requests between any two branches.

This is very useful for hotfixes which have to be merged both to the master branch and the develop branch (at different times, depending on how you deploy your system)

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
QuestiontorourkeView Question on Stackoverflow
Solution 1 - GitmipadiView Answer on Stackoverflow
Solution 2 - GitTyler RickView Answer on Stackoverflow
Solution 3 - GitTushar MittalView Answer on Stackoverflow
Solution 4 - GitRikingView Answer on Stackoverflow
Solution 5 - GitBeanyTheSaneView Answer on Stackoverflow
Solution 6 - GitmarkwusinichView Answer on Stackoverflow
Solution 7 - GitKyleView Answer on Stackoverflow
Solution 8 - GitrshimodaView Answer on Stackoverflow