Collaboration skill: resolving a Git merge conflict

When pair programming or collaborating, two people may change the same part of a file at the same time. When those changes are pushed and pulled, Git may need you to decide how they should be combined.

What is a merge conflict? A conflict happens when Git finds competing changes in the same part of a file and cannot decide which version to keep. Git pauses the pull or merge so that you can make the decision.

1

Identify the conflicted file

After a pull reports a conflict, return to RStudio’s Git pane. Conflicted files are marked with U for unmerged. Select a file and choose Diff to inspect it, then open the file in RStudio’s source editor.

2

Find the conflict markers

Git places both versions in the file between markers like these:

<<<<<<< HEAD
your local version
=======
the incoming version
>>>>>>> origin/main

HEAD is your local version. The content below ======= is the incoming version from GitHub.

3

Decide what the final file should contain

Keep your version, keep the incoming version, or combine the useful parts of both. Delete all three marker lines, save the file, and run the code to confirm that the result still works.

Coordinate with your partner. If you do not understand why a line changed, ask before deleting it. Do not use force push to bypass a conflict.
4

Stage and commit the resolution

  1. In RStudio’s Git pane, select the checkbox beside each resolved file.
  2. Select Commit and review the diff. No conflict markers should remain.
  3. Enter a message such as Resolve merge conflict, then select Commit.
  4. Select Push to send the resolved version to GitHub.

Before you finish