Merge conflicts are not bugs; they are safety mechanisms. When two developers modify the exact same lines of code in the same file in different ways, Git refuses to guess which version is correct. Instead, Git pauses the merge and asks the human developer to resolve the conflict.
When a conflict occurs during git merge, Git alerts you in the terminal:
$ git merge feature/header
Auto-merging src/Navbar.js
CONFLICT (content): Merge conflict in src/Navbar.js
Automatic merge failed; fix conflicts and then commit the result.
Running git status shows unmerged paths:
$ git status
Unmerged paths:
(use "git add ..." to mark resolution)
both modified: src/Navbar.js
If you open src/Navbar.js in your text editor, you will see Git's standard conflict markers:
<<<<<<< HEAD
// Your current branch version (main)
const BRAND_COLOR = "#7d1935";
=======
// The incoming branch version (feature/header)
const BRAND_COLOR = "#0284c7";
>>>>>>> feature/header
<<<<<<< HEAD: Marks the beginning of the conflicting code from your currently checked out branch (e.g. main).=======: The divider separating the two competing versions.>>>>>>> feature/header: Marks the end of the incoming conflicting code from the branch being merged in.<<<<<<<, =======, >>>>>>>) and keep only the final, working code.git add src/Navbar.js.git commit. Git opens your editor with a pre-populated commit message: "Merge branch 'feature/header'". Save and exit to complete!diff3 for Superior ContextBy default, Git shows only your version and their version. By configuring diff3 style, Git also shows the original common ancestor version before either person touched it:
git config --global merge.conflictstyle diff3
Now, conflict blocks display three sections:
<<<<<<< HEAD
const BRAND_COLOR = "#7d1935";
||||||| merged common ancestors
const BRAND_COLOR = "#ffffff";
=======
const BRAND_COLOR = "#0284c7";
>>>>>>> feature/header
Seeing that the original color was #ffffff makes it immediately obvious what each developer changed!
If you get confused during a complex conflict resolution and want to reset back to a clean state as if the merge never happened, run:
git merge --abort
Strengthen your version control mastery by studying these connected classes:
Learn how Git identifies the best common ancestor during automatic merges.
View the exact differences between conflicting files and working trees.
Resolve conflicts one-by-one during interactive or branch rebasing.
Abort failed merges safely with git merge --abort and reset clean state.
Advance your software engineering skills with the next topic in our synchronized curriculum.
Continue to git rebase Fundamentals → Previous: ← Merge Strategies | Full Syllabus