Skip to content

Resolving conflicts

Ben Auer edited this page Oct 8, 2019 · 10 revisions

Sometimes when you do a pull request you will get a "This branch has conflicts that must be resolved" error. In order to merge this pull request you must do a series of steps on the command line. Sometimes it will tell you what to do but sometimes it does not. Suppose we want to merge branch feature/X into develop but it says there are conflicts.

Before you go on, you must make sure develop is up to date in the local clone where you will be doing the following steps. Checkout the develop branch and do a git pull. If you don't do this you will probably end up still not being able to merge! Better yet, just clone the repository fresh do this!

Here is what you do. If you could see the instructions it would say this:

Step 1: From your project repository, bring in the changes and test.

git fetch origin

git checkout -b feature/X

git merge develop

At this point the merge will fail because of the conflicts. You need to manually fix the conflicts. If you do git status, you will see git indicates some file(s) have not been added. You need to hand edit those files, they will have the conflicting code in chevron'ed blocks. Eliminate all the conflicting blocks by taking the changes you want, save, then git add the conflicting file(s). Git commit to complete the merge

Step 2: Merge the changes and update on GitHub.

git checkout develop

git merge --no-ff feature/X

git push origin develop

Notice you can't do this last step because develop is a protected branch. At this point you need to create a new branch and create a pull request with that.

So instead

git checkout -b feature/hand_merge_X

push this to git and issue a pull request from this new branch to develop.