0

I have the following branches:

master
featureA
featureB

on multiple git repositories. Development occurs on all three branches simultaneously. I need to merge featureA into featureB and finally merge featureB into master. Currently I do:

Switch to featureB and merge from featureA. Switch to master and merge from featureB. This procedure involves 2 switches and since I need to do it for approx 7 repositories it takes some time.

Is there a better way to do this using git?

u123
  • 15,603
  • 58
  • 186
  • 303
  • "since I need to do it for approx 7 repositories" - maybe this is the problem. Why seven repositories? Your switches are relatively cheap, though, aren't they? (Assuming you have a clean repository otherwise) And the git commands will be relatively quick anyway compared to any conflict merging you need to do and re-testing the final merged code. – Rup Apr 14 '13 at 11:25
  • Do those seven repositories contain the same code? You usually do the merge only one and push it to any other repositories. – michas Apr 14 '13 at 11:40
  • This is a sign that the seven repositories should be one repository. – alternative Apr 14 '13 at 12:35

6 Answers6

1

You need to do two steps on each of 7 repositories. Sounds like a good case for writing a shell script to run the necessary git commands for you in each repo. I don't think git itself has much for you as long as your repos are separate; you could also look into connecting them via "submodules" (though I'm not exactly sure it will help here).

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
1

This sounds slightly abnormal. If you've got six or seven developers all working on featureA or featureB then they should already be synchronized with one another. That is, during the process of development they were pushing/pulling with one another or indirectly through a designated central repository. This is the how they work together when developing features.

In this scenario the only thing that remains is:

# your 4 steps
git checkout featureB
git merge featureA
git checkout master
git merge featureB

After this, each developer pulls master and they can either delete featureA and featureB or just abandon them.

Development proceeds with each developer creating new feature branches off of master

GoZoner
  • 67,920
  • 20
  • 95
  • 145
1

Git does not natively have much in the way of streamlining multiple branch mergers. I wrote a small CLI called Cascade for just this purpose.

Casecade-CLI: https://www.npmjs.com/package/cascade-cli

It seems the workflow you mention is extremely common, annoying, and can be somewhat time consuming. The CLI will pull each branch from the host (if available), merge, then push each branch back to the host (if available). It's still in its infancy, but I'm planning to extend its functionality and hopefully solve this reoccurring issue.

Usage:

cascade merge <head> <toBranches...>

Example:

cascade merge featureA featureB master 
0

My recommend merging order is the following.

//merge master to featureA
git checkout master
git merge featureA

//merge featureA to master
git checkout featureA
git merge master

//merge master to featureB
git checkout master
git merge featureB

//merge featureB to master
git checkout featureB
git checkout master

In this way, both featureA and featureB modifications are merged to master safely. Also, merge missing does not occur even if there were any master modifications beforehand.

However, the order is complex. That's why there is a possibility to make a mistake the operation if manual. It seems like that there is the tool to automatize the order, please search with Google.

0

Try to run this command:

  • git checkout master
  • git merge featureA featureB

You can merge all the branches you desire in one step. Just create a chain of merges:

  • git merge a b c d e

will merge branches a, b, c, d and e in you current branch.

If one of theme cause a conflict, the merge fails. Obviously.

sensorario
  • 20,262
  • 30
  • 97
  • 159
0

You may want to use automated shell merging script or see how to merge or combine two repos.

lubosdz
  • 4,210
  • 2
  • 29
  • 43