Home > Software design >  How to share code between 2 feature branches
How to share code between 2 feature branches

Time:06-05

Let's say I've written a method in feature1 branch and after some time I realize that I need this piece of code in another feature2 branch as well.

So I just copy/paste the code from feature1 into feature2 and the work simultaneously continues on both branches. I cannot merge feature1 into feature2, because then reviewers of feature2 will also have to check the changes from feature1 as well. Then I ask reviewers to review both features.

Assume feature1 is merged into master and then I want to merge feature2 into master as well. But because of the copy/paste I get a merge conflict, so I have to ask for reviews again. This is not a problem per se. But is there a way to avoid this conflict?

CodePudding user response:

Your question starts with some incorrect assumptions:

  • You can cherry-pick, if you like.
  • Cherry-picking itself does not mean that you will have conflicts. It does not mean that you won't have conflicts either.
  • You can indeed copy-paste some code; as before, this neither causes nor avoids conflicts on its own.
  • Conflicts are not evil! Well, you didn't say they were
  • Related