Course contentsShow
← Computer Science
Lesson 2188 of 2,87249. Version Control with GitFree lesson

Resolving Merge Conflicts

Master the process of manually resolving conflicts by editing conflict markers and staging resolved files.

Resolving Merge Conflicts

You'll learn: How to manually fix merge conflicts by editing conflict markers and staging the resolved files.

The Conflict Resolution Process

When a merge conflict occurs (as you learned in the previous lesson), Git pauses and marks the conflicting sections in your files. Now you need to clean up the mess manually. Think of it like two editors suggesting different edits to the same paragraph—you must decide which version to keep, or blend them together.

Reading Conflict Markers

Git inserts special markers into conflicting files:

<<<<<<< HEAD
Your current branch's content
=======
The other branch's content
>>>>>>> branch-name

The section between <<<<<<< HEAD and ======= shows what's in your current branch. Between ======= and >>>>>>> branch-name is what the other branch has.

Manual Resolution Steps

  1. Open the conflicted file in your text editor
  2. Find the conflict markers (<<<<<<<, =======, >>>>>>>)
  3. Edit the content to keep what you want—delete one version, keep both, or write something new
  4. Remove all conflict markers completely
  5. Stage the resolved file with git add filename
  6. Commit to complete the merge

For example, after resolving conflicts in app.py, you'd run:

git add app.py
git commit

Git will generate a merge commit message automatically, or you can customize it.

Key Takeaway: Resolving merge conflicts requires manually editing files to remove conflict markers and choose the correct content, then staging and committing the resolved version.