1

I am attempting to reconcile two feature branches in git. Automerging is problematic, as the functionality of both of these features cannot coexist. For context, the scenario is like this:

      -------------   Feature A
    /               \
-------------------------   Main
      \       /
        -----   Feature B

Feature A split from Main, and we knew it would take a while to implement. Soon after, we split Feature B to develop it as a stop-gap until Feature A is ready. It implements similar functionality in a different way, and cannot coexist with Feature A. Since Feature B was merged back into Main, necessary commits have occurred on Main that Feature A also needs (otherwise I would just force push the tip of Feature A as the new tip of Main). Note that the nature of incompatibility between the branches is not something git could recognize; it's not conflicting lines of code, but rather separate lines of code using the same resources.

I found this answer as the most straightforward solution, but the consensus there seems to be that this is indicative of a bad workflow or bad practice. How would you handle this situation instead?

  • Undo mergeset(s) B->Main after merging A->Main? – Lazy Badger Jan 26 '22 at 18:30
  • 1
    You could merge `Main` into `Feature A` first. Then, do the clean up (i.e. removal of `Feature B` stuff there) **on** the `Feature A` branch. Then, you can merge `Feature A` into `Main` "safely". `git revert` might be your friend when working on `Feature A` after merging `Main` into it. Alternatively, if you don't want to do the clean up on `Feature A`, you can branch off of `Feature A` before. – Michi Jan 26 '22 at 18:34
  • 1
    @Michi Oh that's obviously the answer, I don't know why I didn't think to do that right away. Want to submit it as answer instead of this comment? – Adam Wolnikowski Jan 26 '22 at 18:39

1 Answers1

1

You could merge Main into Feature A first. Then, do the clean up (i.e. removal of Feature B stuff there) on the Feature A branch. Then, you can merge Feature A into Main "safely".

git revert might be your friend when working on Feature A after merging Main into it.

Alternatively, if you don't want to do the clean up on Feature A, you can branch off of Feature A before (see Replace_B_by_A below).

e.g.

git checkout Feature_A
git checkout -b Replace_B_by_A
git merge Main
# fix commits, e.g. by using `git revert`
git checkout Main
git merge Replace_B_by_A
Michi
  • 681
  • 1
  • 7
  • 25