Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open multiple pull requests on GitHub

People also ask

Can I open multiple pull requests from same branch?

There can be only one open PR from a given branch.

Can we merge two pull requests?

By default, any pull request can be merged at any time, unless the head branch is in conflict with the base branch. However, there may be restrictions on when you can merge a pull request into a specific branch.


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.

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 ]

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.


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.


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.


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.