Web Development · Intermediate level

Intermediate level · Module 2: Collaborating with Git and GitHub · Lesson 3 of 3

Resolving Merge Conflicts

Understand why conflicts happen and resolve them confidently.

In this lesson you will

  • Explain the cause of a merge conflict
  • Resolve conflicts in the editor and complete the merge

Key concepts

merge conflictconflict markersupdating a branch from maintesting after a merge

The lesson

A conflict happens when two branches change the same lines differently. Git cannot choose, so it marks the conflict in the file with <<<<<<<, ======= and >>>>>>> sections showing both versions.

Resolve by editing the file to the correct combined result, removing the markers, then git add and commit. Editors such as VS Code offer buttons to accept one side or both, but you must still check the result makes sense.

Reduce conflicts by keeping branches short-lived, merging main into your branch often and communicating when two people must edit the same file.

Step by step

  1. Create a conflict by editing the same heading on two branches.
  2. Merge and read the conflict markers.
  3. Resolve the conflict and commit.
  4. Test the site after the merge.

Practice activity

Resolve the deliberate conflict in your team repository and document how you decided on the result.

Expected result: The conflict is resolved, the site works and a short note explains the decision.

Check your understanding

  1. When does a merge conflict happen?

    Show answer

    When two branches change the same lines in different ways.

  2. How can teams reduce conflicts?

    Show answer

    Keep branches short-lived, update from main often and coordinate edits to shared files.

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.