Home > Blockchain >  what's best branching stragegy for this scenario?
what's best branching stragegy for this scenario?

Time:09-30

Let's say I have Master branch M and Feature branch F. Both branches are under continuous development. For the next release going production, I only want everything that is in M. Until then there will be daily releases to test environment that include both material from M and F.

Currently I have F branched off M. Every day deploying to Test, I would rebase F branch to M first, and deploy F. This has been pretty good until I had to do manual merges on conflicts. To be honest I am not sure exactly how rebase works. Sometimes I feel like I am resolving the same conflict multiple times in the same session. It seems the longer I keep the 2 branches separate the more I have to resolve the same conflicts for each time I rebase. It seems it could help if I keep editing the same set of files each branch, but sometimes that's not realistic. You need to do what you need to do to complete a feature, right?

What is a good strategy for this scenario?

CodePudding user response:

It's possible you are having to resolve the same conflicts. Rebasing creates a new commit for each commit in your branch. That is, it turns something like

m1 -- m2 -- m3 (M)
 \
  f1 -- f2 -- f3 (F)

into

m1 -- m2 -- m3 (M) -- f1' -- f2' -- f3' (F)

If there is a conflict introduced by f1, you would have to correct it in order to create f1', but then you may have to correct it again to create f2', and so on.

The alternative is to merge M into F, yielding

m1 -- m2 -- m3 ----- (M)
  \                 \
   f1 -- f2 -- f3 -- * (F)

Now any conflicts need to be resolved only once, when the new commit * is created. f1 through f3 remain unchanged, rather than each being replaced by a corresponding new commit.

If it turns out F is ready to be merged into M, you have again only need to create a single new commit (which should be conflict-free since * has already resolved them):

m1 -- m2 -- m3 ---- --- ** (M)
  \                 \ /
   f1 -- f2 -- f3 -- * (F)

To be clear, ** has two parents: * and m3. * also has two parents: m3 and f3.

There is also the rerere command, which can be used to "replay" the same fix made to create f1' when creating f2'. I'll refer you to git help rerere rather than (poorly) recapping it here. (rerere is also useful for avoiding multiple "artificial" merge commits in F; again see the help for a discussion on that topic.)

  • Related