Course contentsShow
← Data Science
Lesson 2011 of 2,14546. Version Control with GitFree lesson

Resolving Merge Conflicts

Reading conflict markers, choosing between changes, and completing the merge with git add and commit.

Resolving Merge Conflicts

You'll learn how to read Git's conflict markers, choose the correct changes, and finalize the merge.

Understanding Conflict Markers

When Git can't automatically merge changes (as introduced in the previous lesson), it marks the conflicted sections in your files with special markers:

<<<<<<< HEAD
Your current branch's version of the code
=======
The incoming branch's version of the code
>>>>>>> feature-branch

Think of these markers like a split-screen comparison. Everything between <<<<<<< HEAD and ======= is what exists in your current branch. Everything between ======= and >>>>>>> feature-branch is what's coming from the branch you're merging in.

Resolving the Conflict

Your job is to decide which version to keep—or combine both intelligently. Open the conflicted file in your editor and:

  1. Read both versions carefully to understand what each branch changed
  2. Edit the section to reflect the desired final state
  3. Remove all conflict markers (<<<<<<<, =======, >>>>>>>)

The file should look normal when you're done, as if the conflict never existed.

Completing the Merge

Once you've resolved all conflicts:

  1. Stage the resolved files with git add <filename> (or git add . for all)
  2. Commit the merge with git commit (Git will provide a default merge commit message)

The staging step tells Git "I've resolved this conflict and this is the correct version." The commit finalizes the merge, creating a new commit that incorporates both branches' histories.

Key Takeaway: Resolving merge conflicts requires manually editing files to remove conflict markers and choose the correct changes, then staging with git add and committing to complete the merge.