2

My situation:

I'm coding on a project, called project, now it's half-done.

But at this moment, I'm asked for another project, called project-cn, 80% same as project, but there are still different features to be develop.

My solution for now:

  1. new branch master-cn from master branch of project;
  2. develop the unique features of project-cn under master-cn;
  3. checkout back to master branch, develop new common feature of both;
  4. Manual copy the new feature modify to the master-cn.

My expectations:

           project-hk
             /   \
            /     \
       master   master-cn
         /           \
        /             \
add feature-hk-1     add feature-cn-1
     |                    |
     |                    |
add feature-hk-2     add feature-cn-2
     |                    |
     |                    |
     |    feature-both    |
     |      /      \      |
     |merge/        \merge|
     |    /          \    |
     |   /            \   |
     |  /              \  |
     | /                \ |
   master              master-cn

My Question:

What should I do ? And where is the feature-both from ? A new branch ? Base on where?

Maroun
  • 94,125
  • 30
  • 188
  • 241
Yin Gang
  • 1,443
  • 1
  • 10
  • 15
  • 1
    You could have your feature_both branch as a submodule of your own repo (as in http://stackoverflow.com/a/35307501/6309) – VonC Mar 16 '16 at 15:08

1 Answers1

1

I think it's a good idea to maintain both a master branch and a master-cn branch.

Only make commits on master that can live on both branches. After you add a feature on master merge it into the master-cn branch.

Eventually, when master-cn is finished, merge it back into master so master effectively becomes feature-both.

For this step:

Manual copy the new feature modify to the master-cn.

I would do this:

git checkout master-cn
git merge master

BUT, if there are commits on master that simply cannot go to master-cn yet you may want to cherry-pick individual commits over:

git checkout master-cn
git cherry-pick a2j233 # sha
git cherry-pick vsdd3f # sha
Jonathan.Brink
  • 23,757
  • 20
  • 73
  • 115
  • Thanks, @Jonathan.Brink. But how about there are commits on `master-cn` that simply cannot go to `master`? – Yin Gang Mar 16 '16 at 13:03
  • @smallyin if that is the case, then you may need to have a separate branch `feature-both` as you stated in your original question. It would be nice to integrate everything back into `master` so you can just maintain a single line of work, but I understand that's not realistic in some cases – Jonathan.Brink Mar 16 '16 at 13:05
  • @smallyin So, is it possible to periodically merge `master` into `master-cn` and use that as your feature branch, rather than having a separate `feature-both` branch? Just looking to cut down on the number of branches to be maintained – Jonathan.Brink Mar 16 '16 at 13:06