Git Conflict Resolution
In this page:
What is a Merge Conflict?
A merge conflict happens when the branch you're merging in and your current branch both changed the same lines of the same file since they diverged, so Git has no way to automatically decide which version is correct and pauses the merge for you to resolve it by hand.
Example: What is a Merge Conflict?
git merge feature-x
# CONFLICT (content): Merge conflict in file.txt
Understanding Conflict Markers
Git marks each conflicting section directly in the file with <<<<<<<, =======, and >>>>>>> lines separating "your" version from "their" version. Resolving the conflict means editing the file to keep the correct content — from one side, the other, or a manual combination — and deleting all three marker lines completely.
Example: Understanding Conflict Markers
<<<<<<< HEAD
your version
=======
their version
>>>>>>> feature-x
Staging and Committing the Resolution
Once every conflict marker is gone and the file reflects the outcome you want, git add <file> stages the resolution and git commit finishes the merge — Git already knows a merge was in progress, so it pre-fills a merge commit message for you.
Example: Staging and Committing the Resolution
git add file.txt
git commit
Aborting a Conflicting Merge
If a conflict turns out to be more trouble than it's worth to resolve right now, git merge --abort cancels the merge entirely and returns your branch to exactly the state it was in before you started — a full escape hatch as long as you haven't already committed the resolution.
Example: Aborting a Conflicting Merge
git merge --abort
Resolving Conflicts During a Rebase
Conflicts during a rebase work the same way file-wise, but the continuation command differs: after fixing and staging the file, you run git rebase --continue (not commit) to move on to replaying the next commit — and each subsequent commit in the rebase can trigger its own separate conflict.
Example: Resolving Conflicts During a Rebase
git add file.txt
git rebase --continue
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: