Skip to main content

Merge Conflicts

Learn what merge conflicts are and ways to solve them.

What is a Merge Conflict?

A merge conflict in Git occurs when more than one change has been made to the same line of code or section of a file, and Git cannot automatically decide which change to keep and which to discard. This typically happens when at least two people have made changes to the same area in a file.

Merge Conflict Modal

When a merge conflict happens, you’ll resolve it in this modal.

The image displays a Merge Conflict resolution interface in Coalesce for the file `TARGET-Staging_Orders_One_Two.yml`. The interface highlights conflicting lines between the current branch (labeled as `main`) and the incoming changes (labeled as `refs/remotes/origin/merge_conflict_three`). The user is provided with options to either Keep Current changes or Accept Incoming changes, with additional controls to view all file changes and navigate between conflicts. At the bottom, there are options to Abort or Merge after resolving the conflict, along with a link to the Coalesce documentation for further guidance on handling merge conflicts.
  1. The name of the file the conflict happened in.
  2. The option to either accept or reject all changes at once. Green is your changes and Blue are the changes that are coming from the remote or other branch.
  3. Navigation arrows that allow you to move between each merge conflict.
  4. The main window where you can edit the file.
  5. You can either Abort the change or Merge. You can only merge after all conflicts are resolved.

What to Know Before Solving Merge Conflicts

  • Local Changes - These are changes you made locally that haven’t been pushed to your Git repository. They only exist locally for you.
  • Remote Changes - Remote is the term used for the location of your “main” repository. These changes have been made by others and are present in the remote repository. You encounter these changes when you fetch or pull updates from the remote repository.
  • Keep Current - These are all changes highlighted in green. These are the changes you made or the current branch you are working on.
  • Accept Incoming - These changes are highlighted in blue. These are the changes you want to bring in.

Understanding a Merge Conflict

If a merge conflict occurs, Coalesce will pause the merging process and mark the file where the conflict exists. Understanding conflict markers is crucial to resolving conflicts.

  • Conflict Start Marker (<<<<<<<): This marker indicates the beginning of the conflicting area and is followed by your local changes.
  • Base Marker (=======): This marker separates your changes from the changes in the remote branch.
  • Conflict End Marker (>>>>>>>): This marker indicates the end of the conflicting area and is followed by the incoming changes from the remote branch.
The image shows a Merge Conflict interface in Coalesce for the file TARGET-Staging_Orders_One_Two.yml. The conflict arises between two branches: refs/heads/main and refs/remotes/origin/merge_conflict_three. The conflict is specifically on the description field, where the main branch has Main description and the incoming branch has Lorem Ipsum. The interface offers options to Keep Current changes from the main branch or Accept Incoming changes from the merge branch. Additionally, there are options to view all file changes, abort the merge, or finalize it after resolving the conflict. There is also a prompt to view the Coalesce documentation for more information on resolving merge conflicts.
deployEnabled: true
<<<<<<< refs/heads/main
description: Main description
=======
description: Lorem Ipsum
>>>>>>> refs/remotes/origin/merge_conflict_three
isMultisource: false

In this example, your local changes are description: Main description and you want to merge into the remote. But there is a conflict because the remote has description: Lorem Ipsum.

To fix this error, you would remove all the other lines except for your changes. You can do this manually by deleting lines or if you are fine with all the changes, you can select Keep Current Changes. Watch out for empty lines.

The image shows a Merge Conflict interface in Coalesce for the file TARGET-Staging_Orders_One_Two.yml. The conflict has been resolved by keeping the main branch's description, and the user has the option to abort or finalize the merge.
Searching for Merge Conflicts

You can use your operating system's search functionality within the Merge Conflict Window by clicking CTRL + F or Command + F once your cursor is in the text box.

Large Merge Conflicts

There are times that conflicts are too complex to resolve within Coalesce and require going through the git provider's platform to resolve before merging the branches/commits. Our system will make you aware if this is the case and warn you accordingly. If you have a use case where you're running into this situation often, please reach out to our Support team.

General Steps to Resolve Merge Conflicts

  1. Identify the Conflicted Files: Coalesce will return all the files with conflicts.
  2. Review the Markers: Use the conflict markers to understand the differences between your local changes and the remote changes. Look at the code between the start and base markers to see your changes, and between the base and end markers to see the remote changes.
  3. Decide on the Changes to Keep: You need to decide whether to keep your local changes, accept the remote changes, or combine both. Ask your team to make sure you aren’t removing important work.
  4. Edit the File: Remove the conflict markers and make the necessary edits to the file to incorporate the chosen changes. Ensure that the code's functionality and syntax are correct.
  5. Complete the Merge: Continue with the merging process. Once all conflicts are resolved and the merge is successful, push your changes to the remote repository to share them with others.