🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Git Notes
Topic #45

Git Merge Conflicts


What is a Merge Conflict?

A merge conflict happens when two branches change the same part of a file.

Git can't decide which change to keep, so you have to choose.

You must resolve the conflict before you can finish the merge.


Why Do Merge Conflicts Happen?

Merge conflicts usually happen when you merge branches that changed the same lines in a file.

This is common in collaborative projects or when working on long-lived branches.


How to See and Resolve Merge Conflicts

When you merge a branch and there are conflicting changes, Git will pause and mark the files with conflicts.

Example: Merge a Branch

git merge feature-branch

If there are conflicts, Git will tell you which files are affected.


See Which Files Have Conflicts

Use git status to see which files need your attention:

Example: Check Status

git status

See the Differences

Use git diff to see what changed and help you decide how to resolve the conflict:

Example: See Differences

git diff

Edit the Conflict Markers

Open the conflicted file. You'll see sections like this:

Conflict Markers

<<<<<<< HEAD
Your changes here
=======
Other branch's changes
>>>>>>> feature-branch

Edit the file to keep what you want, then remove the conflict markers (<<<<<<<, =======, >>>>>>>).


Mark as Resolved

After fixing the file, mark it as resolved:

Example: Mark Resolved

git add filename.txt

Complete the Merge

Finish the merge with a commit (if Git doesn't do it automatically):

Example: Finish Merge

git commit

Cancel the Merge

If you want to stop and undo the merge:

Example: Abort Merge

git merge --abort

Use a Visual Merge Tool

If you prefer, you can use a visual tool to resolve conflicts:

Example: Use Mergetool

git mergetool

Pick One Side's Changes

If you want to keep only your changes or only the other branch's changes:

Example: Keep Our Changes

git checkout --ours filename.txt

Example: Keep Their Changes

git checkout --theirs filename.txt

Troubleshooting & Best Practices

  • If you're stuck, you can always use git merge --abort to start over.
  • Make sure you remove all conflict markers before marking as resolved.
  • If you use git mergetool and don't like the result, you can still edit the files by hand.

Want to go beyond the notes?

Join CodingNow 2.0's Git course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Git Merge Conflicts – FAQs

Quick answers about learning Git Merge Conflicts in Git.

This free note from CodingNow 2.0 explains Git Merge Conflicts in Git — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Git topic on CodingNow 2.0, including Git Merge Conflicts, is 100% free with no signup required.
With focused practice, most students grasp Git Merge Conflicts in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now