Handling Merge Conflicts

Merge conflicts often occur when multiple users are concurrently making edits to the same section in the same file. This makes it difficult for Git to determine which change should be kept. The merge conflict process gives users the ability to sort out which lines of code should be kept and committed. Here we'll show you how you'd resolve merge conflicts in the IDE!

Running into a merge conflict

In this example we have a column that represents the total number of orders your customer has ever had. It's currently named number_of_orders but your stakeholder feels like this could be named better.

You and a teammate make changes to the column name, but have gone two separate routes. You rename this column to total_number_of_orders and your teammate has renamed it historical_order_count.

Your teammate has committed their change first, so you encounter a merge conflict when you press commit.

Commit which will trigger the merge conflict

Commit which will trigger the merge conflict

You will then see that the git action bar shows commit and resolve... instead of commit indicating that the Cloud IDE has detected some conflicts that need to be addressed. You should also see the conflict section marked with some flags:

<<<<<< HEAD
your current code
======
conflicting code
>>>>>> (some branch identifier)
Conflicting section that needs resolution will be highlighted

Conflicting section that needs resolution will be highlighted

File and path are colored in red with a warning sign to highlight files that need to be resolved

File and path are colored in red with a warning sign to highlight files that need to be resolved

Pressing commit without resolving the conflict will also list which files need to be addressed

Pressing commit without resolving the conflict will also list which files need to be addressed

Encountering Merge Conflicts

You could run into this merge conflict in 2 possible ways:

  • Pulling changes from your main branch when someone else has merged a conflicting change
  • Committing your changes to the same branch when someone else has already committed their change first (this scenario)

The way to resolve either scenario will be exactly the same!

Resolving conflicts

Choosing lines to keep

Choosing lines to keep

  1. Choose which lines of code you'd like to preserve. Delete the rest, make sure to also delete the special flags that highlight the merge conflict.
  2. Press save! You will notice the line highlights disappearing, returning to a plain white background, which is a good sign that you've resolved the conflict successfully!

Repeat this process for every file that has a merge conflict.

Completing the process

When you've resolved all the merge conflicts, the last step would be to commit the changes you've made!

The easiest way to identify whether you've successfully resolved all conflicts would be to check the file tree. If all the files highlighted in red have a file icon next to it, instead of the warning sign, you should be good to go!

Conflict still needs to be resolved

Conflict still needs to be resolved

Conflict has been resolved!

Conflict has been resolved!

You will also know it's time to commit when you press the commit and resolve... button and the modal does not have any warning messages about unresolved merge conflicts!

Commit modal with a warning highlighting unresolved merge conflicts

Commit modal with a warning highlighting unresolved merge conflicts

Clean commit modal that's ready to be committed

Clean commit modal that's ready to be committed

When you're ready, write your commit message as you normally would and press the Commit button!

Commit merge conflict resolution

Commit merge conflict resolution