Resolving Pull Request Conflicts

Overview

This article explains the reasons behind Pull Request conflicts and the common scenarios in which they occur. It also provides detailed, step-by-step instructions for reviewing and resolving these conflicts effectively.

What causes a Pull Request conflict?

A Pull Request conflict can occur when two branches have commits that affect the same line of code, and the Pull Request is unable to automatically determine which line to preserve. To illustrate how this can happen, see the diagram below.

In this example, branch_b is created from branch_a. Next, a change affecting the myName function is committed to branch_b, and a different change to the function is committed to branch_a. When a Pull Request is created to merge branch_b into branch_a, the pull request detects that the same line of code has changed in both branches, resulting in a conflict. In the following section, you will see two different options for resolving the conflict.

How to resolve a Pull Request conflict?

When a Pull Request encounters a conflict, you can resolve it by either retaining or overwriting the target's changes. For multiple conflicts, address each one separately using the most appropriate method; it's okay to use different approaches for different conflicts.

chevron-rightRetain Target Changeshashtag

To resolve conflicts using this method, commit the conflicting lines from the target branch into the source branch. See the diagram for an illustration, and refer to the step-by-step instructions provided in the Retain Target Changes section below.

circle-info

This method uses the Resolve Conflicts function in a Pull Request to automatically commit the changes to the source branch.

chevron-rightOverwrite Target Changeshashtag

To resolve conflicts using this method, commit the conflicting lines from the source branch into the target branch. See the diagram for an illustration, and refer to the step-by-step instructions provided in the Overwrite Target Changes section below.

circle-info

This method requires you to manually commit the changes from the source branch into the target branch.

Resolving Conflicts

1

Pull Request Conflicts

When a Pull Request is created, a conflict check is run initially. If any conflicts between the Target and Source branches are found, a warning will be displayed, and you must resolve the conflicts before the Pull Request can be merged.

2

Review Conflicts

  1. Click Resolve conflicts.

  2. Click a component to view the conflicts.

circle-exclamation
  1. Review the conflicting code in the component and determine how to resolve the conflict.

circle-info

See the What causes a Pull Request conflict? section above for an explanation of Pull Request conflicts.

  1. There are two ways to resolve a Pull Request conflict. See the following sections for instructions about how to perform each.

    1. Retain Target Changes: This method keeps the target's code by committing the conflicting lines from the target branch into the source branch.

    2. Overwrite Target Changes: This method keeps the source's code by committing the conflicting lines from the source branch to the target branch.

circle-info

For multiple conflicts, address each one separately using the most appropriate method; it's okay to use different approaches for different conflicts.

3

Retain Target Changes

This method uses the Resolve conflicts feature built into a Pull Request.

  1. Click a component with conflicts to resolve.

  2. Click Accept all to retain all lines, or click the Right Arrow for each line to retain. This copies the selected line from the target branch to the source branch.

  3. Once all necessary changes have been made to the source branch, click Resolve. This marks a component as Resolved so you can keep track of your changes.

  4. Click Back.

circle-info

Repeat this process for all components with conflicts.

  1. Once all components are marked as Resolved, click Resolve conflicts.

  2. Enter a Commit message.

  3. Click Resolve.

  4. After resolving the conflicts, the Pull Request will check for conflicts again.

  5. If there are no more conflicts, the Pull Request message will be green and state "This branch is able to merge".

circle-info

If conflicts persist in the Pull Request, review and resolve them. Repeat until all issues are resolved.

4

Overwrite Target Changes

This method requires manually editing and committing changes to the target branch.

circle-info

To make it easier to resolve conflicts when overwriting changes in the target branch, note the specific lines and components causing conflicts as you review the Pull Request.

  1. Click Code from the left sidebar menu.

  2. Click the target branch of the Pull Request.

  3. Click the Three Vertical dots at the right end of a component with conflicts in the Pull Request.

  4. Click Edit.

  5. Edit the conflicting line or lines of code to match the source branch.

  6. Click Commit changes.

  7. Enter a Commit message.

  8. Click Commit.

circle-info

Repeat this process for all components with conflicts.

  1. Once all components with conflicts are edited to match the source branch, return to the Pull Request.

  2. Click Pull requests from the left sidebar menu.

  3. Click the Pull Request to check if all conflicts are resolved.

  4. If there are no more conflicts, the Pull Request message will be green and state "This branch is able to merge".

circle-info

If conflicts persist in the Pull Request, review and resolve them. Repeat until all issues are resolved.

Last updated

Was this helpful?