0

I'm working on a test suite for our application. My work goes into branch B. Meanwhile someone else is working on branch A.

I want to periodically merge B into A with --squash, and after fixing the conflicts, update B to look like A.

Most importantly, I need git to understand that after I do the above, there should be a new merge base.

I don't want to create a new branch "B_2" after, because I want my history of B to be in one place. (And A does not need to be polluted with work-in-progress commits from B, hence the squash).

I also don't want to rebase all the work in B on top of A, because it's possible that the changes in the original commits of B won't make any sense when replayed on top of a modified code base from A.

My initial attempt was:

git checkout A
git merge B --squash
*fix conflicts, commit*
git checkout B
git merge -s recursive -X theirs A --squash

This lets me have two near identical branch heads, except that the merge-base of the two branches is the original commit from which branch B was split off. Further merges then become a nightmare.

Is there some preferably not too convoluted way of doing what I want?

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
mr. alex
  • 71
  • 3
  • My preferred way is "don't use `--squash`". If you insist on doing squash merges, however, you'll have to do an additional merge in the "other direction" to establish a new merge base. I have answered this before but can't find my old answer off-hand. – torek Aug 15 '16 at 18:01
  • 1
    Having long-lived, mutually interdependent feature branches is not going to be any fun. Push smaller pieces to master when they're ready, or develop your branch in isolation and then do the one big merge when needed. –  Aug 15 '16 at 19:14
  • "I want to periodically merge B into A ... and ... update B to look like A." Why? I believe you that you have a good reason - can you share it with us? – AnoE Aug 18 '16 at 13:32
  • I'm writing a testing suite. This will take a long time, I'm talking months here. When a certain subset of tests is done, I want the other devs to have access to them. I also inevitably find bugs, so my tests come with fixes. If I found the bug in the middle of writing a test, it's way faster to just add the fix to the same commit as the test, especially if the test was essential in ensuring that the bug is indeed fixed. And once one merge of B into A is done, why would I continue working on an obsolete version of B? – mr. alex Aug 18 '16 at 16:51
  • @torek Would [this](http://stackoverflow.com/questions/37352976/how-to-make-squash-default-on-a-merge/37828622) be it? I guess I'll have to settle for your method. It's almost what I need, minus the A->B merge not being squashed, but I can live with that. After a few hours of reading, it seems like there is no other way. Not sure why this is so much to ask for. – mr. alex Aug 18 '16 at 20:39
  • @mr.alex: yes, that's the one. – torek Aug 18 '16 at 20:51

0 Answers0