Search code examples
gitgit-mergeconflictsquash

How to resolve conflicts of merge --squash via command line of a protected branch?


I am trying to merge --squash a feature branch to master (which is protected and cannot be pushed to),
and there are conflicts. So the auto-merge is failing and I get a message that it should be done by the command line with some instructions:

  1. fetch both

  2. checkout the protected branch (master)

  3. run the merge command

  4. resolve conflicts

  5. push to the protected branch (master)
    This of course is failing because I can't push to the protected branch. And so I am left with conflicts and unable to merge the branch.

Is there a correct way to merge --squash a branch into a protected one?
How can I resolve these conflicts?


Solution

  • This means your branch is behind the master branch and master moved ahead and there could be changes in the same file/same line which git can't resolve automatically. You can rebase it onto the master first, resolve conflicts if any and push your branch to remote.

    git fetch origin
    git checkout master
    git pull origin master
    git checkout <your branch>
    git rebase master
    git push --force origin <your branch>
    

    Now your branch will be up to to date with master and then you do what you were doing earlier.