Solve PR merge conflict when merging feature into test from main

Issue

I’ve run into a problem where a Feature branch was created from the Main branch, and a conflict occurs when merging into the Test branch. How can I solve this conflict without merging the Test branch into the Feature branch (which will lead to the Test branch being merged into Main afterwards), or merging the Feature branch directly into the Test branch, ignoring the pull request?

Solution

You could create an "integration", "conflict resolution", or "feature-test" branch. But note that this means you will have different code in your test branch (after merge) as compared to the code that ends up in your main branch.

git checkout -b feature-test feature
git merge test
# resolve conflicts
# commit conflict resolution (will contain changes from test _and_ feature)
# run your tests
# ...
# if everything successful, merge your original, still-unchanged feature branch
git checkout main
git merge feature

The commit with the conflict resolution will only exist on "feature-test".

You could also switch the order of how the branches are merged (test into feature vs. feature into test):

git checkout -b feature-test test
git merge feature
# optional: fast-forward test to include the conflict resolution: git push . HEAD:test
# resolve conflicts
# commit conflict resolution (will contain changes from test _and_ feature)
# run your tests
# ...
# if everything successful, merge your original, still-unchanged feature branch
git checkout main
git merge feature

Answered By – knittl

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published