Consider the following practice:
- A developer branches from
mainand creates as many commits as needed in a feature branch - Once the feature is completed, all commits are squashed and merged into the
mainbranch (for instance, think of a GitHub's "Squash and merge" button)
And now this is a use case that interests me:
- Create and work on a
feature1branch - Create a
feature2branch starting from the last commit of thefeature1branch (see theCcommit in the image below) - Squash and merge
feature1intomain(see the commitG) - Merge this newly created commit
Ginto thefeature2branch - Continue working on the
feature2branch
In other words, the merge of G into the feature2 branch in step 4 looks like this:
user@host:~/repo (main)$ git checkout feature2
user@host:~/repo (feature2)$ git merge main # merge G into feature2
Often, this merge (see the commit H) results in a number of merge conflicts.
How to completely eliminate these conflicts?
The easiest solution I can think of is the following (see the image below):
user@host:~/repo (main)$ git checkout feature1
user@host:~/repo (feature1)$ git merge main # merge G into feature1; essentially, an empty commit
user@host:~/repo (feature1)$ git checkout feature2
user@host:~/repo (feature2)$ git merge feature1 # merge G' into feature2
To put it another way, instead of merging G into feature2 directly, we first merge G into feature1 and then merge feature1 into feature2.
Is there a simpler approach?

