Reputation: 2335
We have pull requests coming from other forks as well as branches within our own fork that has to go to multiple branches. Is there a way we can merge pull requests to multiple branches in one step?
Upvotes: 15
Views: 30223
Reputation: 677
This should have been implemented into GitHub to make sure commits into release branches are also merged into master.
Plugins (3rd party apps) could help but not for free (unless your project is open-source). https://github.com/marketplace/mergify
Upvotes: 4
Reputation: 2131
Not in one step, but one workaround:
I'm going to assume the branch that your pull request is based off of (and all of the other branches that you want to merge the pr into) are rebased against master. If not then rebase all of them with:
$ git rebase origin/master
What we're going to do is take the diff of your pull request, stash it, and then apply the stash to multiple branches. To make this easier, I'd recommend squashing your commits first. Once you squash them, we're going to undo your last commit (the changes will remain since we're using the soft
flag, but we want to hold on to the changes in our stash).
$ git reset --soft HEAD^
Now we want to reapply them to this branch:
$ git stash apply
Note that I used apply
and not pop
, this ensures that the changes are not dropped. Switch over to your other branches and apply the stash on those as well and commit the changes. Note: When you commit, you're going to have different commit SHA's (because those are all different changes applied to different branches). What this means is you're going to have conflicts if those branches ever come to merge, but hopefully it's easy since the changes should be the same. That being said, I definitely don't recommend this route. Here's what I recommend.
You should be merging that change onto the master branch and rebasing the other branches. Life's so much easier if you do that.
Upvotes: -2
Reputation: 7464
No, you can't unfortunately: http://git-scm.com/docs/git-merge
When I have that requirement (which is not that often), I usually do it manually in the console. If that is a big burden on your workflow I would suggest a shell-script that could first do all the merges without conflicts and then let you manually fix the others.
Is this a requirement because you have too many concurrent development lines at the same time?
Upvotes: 5