Search code examples
gitgithubpull-request

Resolving merge conflicts between protected branches


feature (protected) has conflicts with main (protected) which I cannot resolve.

I have researched many solutions on and off SO and they all come back to a similar answer involving a third branch (fix in this example).

My steps to resolve (intentionally verbose):

  1. See that the conflicts exist on a PR into main from feature
  2. git switch -c fix origin/feature --no-track
  3. git checkout main && git pull
  4. git checkout fix
  5. git merge main
  6. Fix merge conflicts, git add ., git commit etc
  7. Push, create new PR, review, merge into feature
  8. See that the same conflicts still exist on the PR into main from feature

I tried this on a new (public) repo I created and it worked fine. But on my work project repo it does not and I cannot fathom why.

EDIT: I have since tried git rebase main at step 5 instead and worked through the conflicts, but the end result on the PR at step 8 was no different.


Solution

  • Check that the PR is being merged not squashed to retain the history.

    In step 7 I was squashing which was ruining the history.