Merge conflicts occur when competing changes are made to the same line of a file, or when one person edits a file and another person deletes the same file.
To resolve a merge conflict caused by competing for line changes, you must choose which changes to incorporate from the different branches in a new commit.
For example, if you and another person both edited the file styleguide.md on the same lines in different branches of the same Git repository, you’ll get a merge conflict error when you try to merge these branches. You must resolve this merge conflict with a new commit before you can merge these branches.
Steps to Merge Conflicts
- Commit your latest code.
- Get pull from a remote branch, you will see conflicts file shown under your unstage section.
- Open the file on any editor like eclipse etc.
- To see the beginning of the merge conflict in your file, search the file for the conflict marker <<<<<<<. When you open the file in your text editor, you’ll see the changes from the HEAD or base branch after the line <<<<<<< HEAD. Next, you’ll see =======, which divides your changes from the changes in the other branch, followed by >>>>>>> BRANCH-NAME. In this example, one person wrote “open an issue” in the base or HEAD branch and another person wrote “ask your question in IRC” in the compare branch or branch-a
- Decide if you want to keep only your branch’s changes, keep only the other branch’s changes, or make a brand new change, which may incorporate changes from both branches. Delete the conflict markers <<<<<<<, =======, >>>>>>> and make the changes you want in the final merge.
- Add or stage your changes.
- Commit and push your changes as per previous slides.
You may also like: How to Clone a new Repository in GitHub?