Skip to content

Merge Conflict

Quick summary

Git stopped mid-merge because both branches edited the same lines — you must manually choose which version to keep.

Why this happens

  • Both branches modified the same lines of the same file

  • One branch deleted a file while the other modified it

  • Conflicting changes were made to overlapping regions

Minimal example

✗ Broken code
<<<<<<< HEAD
const port = 3000;
=======
const port = 8080;
>>>>>>> feature-branch
✓ Fixed code
const port = 8080;  // resolved: use the feature branch's value

Both branches set port to different values — choose the correct one (8080), remove the conflict markers, and commit.

How to diagnose

  • Run git status to see which files have conflicts

  • Open the conflicted files and look for <<<<<<<, =======, and >>>>>>> markers

  • Review both versions to understand what each branch changed

How to fix

  • Edit each conflicted file to keep the correct version and remove the markers

  • Run git add <file> to mark the conflict as resolved

  • Run git commit (or git merge --continue) to complete the merge

How to prevent

  • Pull from the remote frequently to keep your branch up to date

  • Keep feature branches short and merge them quickly

  • Communicate with your team to avoid editing the same files simultaneously

Related Resources

Related Glossary

Related Lessons

Related Practice

← Back to language