173

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?

Ahmed Nabil
  • 17,392
  • 11
  • 61
  • 88
torourke
  • 1,879
  • 2
  • 13
  • 10

8 Answers8

143

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.
Ahmed Nabil
  • 17,392
  • 11
  • 61
  • 88
mipadi
  • 398,885
  • 90
  • 523
  • 479
  • 3
    Ok thats cool, I thought it was only with the master. So what you mean is I can create many branch ( ie: git flow features ) and make pull requests for each of them... Going to try! – Ziyan Junaideen Nov 20 '13 at 05:24
  • 13
    I just found that the branch preserved the history of the previous commits, so a pull request against the upstream still includes all commits. – eel ghEEz Apr 01 '16 at 16:57
  • 3
    Hi @eel-gheez, did you figure out what to do about this? How to create isolated PRs without the changes from other branches being shown? – Jonathan Cross Oct 12 '16 at 23:43
  • 3
    This does not solve the issue: When I try to create a PR both branches (with at least one commit each) are compared. What am I doing wrong? – MERose Dec 28 '16 at 18:24
  • 1
    @eelghEEz You should create a new branch, [git cherry-pick](https://git-scm.com/docs/git-cherry-pick) all the commits you want to this branch and then make a pull request from this branch. It is a very important design feature of git that each commit depends on its previous commit, and commits in git should not be though of as just a patch, but as a patch knowing what patch was applied before this. So this is why one should create a new branch with new commits, whose diffs are maybe still the same, but whose links to the previous commits are different. – Maarten Derickx Sep 05 '17 at 14:50
12

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.

Martin
  • 2,411
  • 11
  • 28
  • 30
Tushar Mittal
  • 121
  • 2
  • 4
11

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 ]
Tyler Rick
  • 9,191
  • 6
  • 60
  • 60
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.

Riking
  • 2,389
  • 1
  • 24
  • 36
  • You must leave other/master as left side even if your are adding a commit number from yours/master. Also this method does not allow you to add new commits to the merge request, in case some more changes are needed. – frisco Jun 18 '12 at 15:49
  • I posted a followup of sorts to this answer, in contrast to some info on Github, see http://stackoverflow.com/questions/23159860 – Mark Bennett Apr 18 '14 at 19:06
  • I can see this would create two PRs that look correct, in that they each contained exactly the desired commits. But, to be explicit, does it do the right thing when they get merged? As in, I can see that the first PR would correctly merge B & C into other/master. But when the 2nd PR merges, how does it know what branch to merge into? (Since it was created on commit 'C', not on other/master) Does it matter which order the PRs get merged? (presumably so) – Jonathan Hartley Mar 12 '18 at 20:42
1

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.

BeanyTheSane
  • 51
  • 2
  • 4
1

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.

markwusinich
  • 108
  • 7
  • 1
    I believe you have a typo, where you say "Now create a new branch mini_change_3 and PR that to mini_change_3.", don't you mean "Now create a new branch mini_change_3 and PR that to mini_change_2." ? – TonyG Apr 29 '21 at 17:27
0

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
Kyle
  • 3,935
  • 2
  • 30
  • 44
0

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)

rshimoda
  • 1,137
  • 1
  • 13
  • 24