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
- Open the conflicted file in your text editor
- Find the conflict markers (
<<<<<<<,=======,>>>>>>>) - Edit the content to keep what you want—delete one version, keep both, or write something new
- Remove all conflict markers completely
- Stage the resolved file with
git add filename - 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.