Resolving Merge
Conflicts
Learn how Git detects conflicting changes, how to read conflict markers, and how to resolve them cleanly in your Python projects.
What Is a Merge Conflict?
A merge conflict occurs when two branches modify the same lines of the same file, and Git cannot automatically determine which version to keep. Instead of guessing, Git pauses and asks you to decide.
Why Do Conflicts Happen?
When Conflicts Don't Happen
Git is actually very smart. It can auto-merge when changes are in different files or even different lines of the same file. Conflicts only arise when the exact same lines are modified.
The Anatomy of Conflict Markers
When a conflict occurs, Git inserts special conflict markers directly into the file. There are three markers that divide the conflicting sections:
Reading the Three Sections
Merge vs Rebase Conflicts
Both merge and rebase can produce conflicts. The markers look the same, but the context differs:
| git merge | git rebase | |
|---|---|---|
| HEAD means | Your current branch tip | The branch you're rebasing onto |
| Incoming means | The branch being merged in | Your own commit being replayed |
| Resolve then run | git add + git commit | git add + git rebase --continue |
| Abort with | git merge --abort | git rebase --abort |
How to Resolve Step by Step
Example 1: Keep One Side
The simplest resolution: you decide one version is correct and delete the other entirely.
Example 2: Combine Both Sides
Sometimes both changes are valuable and should be merged together into a new version.
Example 3: Multi-line Conflict
Real-world conflicts often span multiple lines. Read each section carefully and understand the intent before resolving.
The Resolution Workflow
Three Resolution Strategies
Useful Git Commands
Common Mistakes
Resolution Cheat Sheet
| Scenario | Action | Command |
|---|---|---|
| See conflicted files | Check status | git status |
| Keep your version entirely | Accept ours | git checkout --ours file |
| Keep their version entirely | Accept theirs | git checkout --theirs file |
| Manually combine both | Edit + remove markers | edit file, git add, git commit |
| Cancel the merge | Abort | git merge --abort |
Question 1 of 5
What does the ======= marker represent in a merge conflict?
Question 2 of 5
You run git merge feature-login and see this in app.py:
<<<<<<< HEAD
username = input("User: ")
=======
username = input("Username: ")
>>>>>>> feature-login
You want to keep the version from feature-login. Which line should remain after resolving?
Question 3 of 5
After manually editing a conflicted file to resolve the conflict, what must you do before committing?
Question 4 of 5
Which command lets you cancel a merge that has caused conflicts and return to the state before the merge?
Question 5 of 5
Two developers work on the same Python file. Developer A changes line 10 to:
MAX_RETRIES = 5
Developer B changes line 10 to:
MAX_RETRIES = 10
Developer A merges main. Then Developer B tries to merge.
What will happen when Developer B runs git merge?