Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub - how to submit individual pull request in case of multiple commits

Tags:

github

I've made multiple commits to my local repository and now I intend to do pull request to submit these changes over to the source/master.

When I do a pull request, it automatically includes all of my commits. I couldn't locate a way to submit each commit in its own pull request. Could someone please give some pointer on how to do this on GitHub.

Update To clarify on this question, I forked a new local repo from upstream/master. Then, in my noobie-ness, I made new files in my local master itself without branching repo out first. So, effectively, my question is with these changes committed to local master repo, is there a way to raise pull requests for each new file one by one, and not for all of them in one go.

Many Thanks.

like image 340
Sunshine Avatar asked Jun 07 '13 12:06

Sunshine


People also ask

How do I create a pull request for multiple commits?

Once you've committed changes to your local copy of the repository, click the Create Pull Request icon. Check that the local branch and repository you're merging from, and the remote branch and repository you're merging into, are correct. Then give the pull request a title and a description. Click Create.

Can a pull request contain multiple commits?

Yes, it will. This includes merge commits, by the way, so if a different branch than the target branch of the pull request is merged in to the branch, then the merge commit and both of its parent chains of commits (from both branches) will become part of the PR.

How many commits Should a pull request have?

Have one commit per logical change and one major feature per pull request. When you submit a pull request, all the commits associated with that pull request should be related to the same major feature.


2 Answers

I'm not sure if there is a better way in GitHub, but in general, you can create a new branch for each pull request, cherry-picking the commits you want for each request. The new branches should preferably be based on upstream master to make the merge painless.

Using command line git, using origin as your own github remote repo, upstream is the upstream remote:

git checkout -b {my_pull_request_feature_branch} upstream/master
git cherry-pick {sha1_of_first_commit_for_feature_X} [sha1_of_another_commit_for_feature_X] ...
git push origin {my_pull_request_feature_branch}

Repeat for each pull request.

When you do a pull request on GitHub you can then choose which branch you want to send in your request.

like image 188
Joakim Nohlgård Avatar answered Oct 04 '22 06:10

Joakim Nohlgård


A commit does not stand on its own, it always links to the full previous history. So if you ask to pull commit B which depends on your commit A, then you are also asking to pull A, because your work in B depends on it.

If you want to submit multiple independent pull requests, you should make sure that those commits are completely independent of each other. So they should be on their own branches. This also makes it easier for the project maintainers to integrate your pull request, as they can just merge the branch without having to cherry-pick stuff.

like image 28
poke Avatar answered Oct 04 '22 05:10

poke