Lessons in this course (10)

4. Merge conflicts — why they happen and how to resolve them

Intermediate★ Must knowLesson 4 of 10

A conflict happens when two branches change the same lines (or one edits a file the other deleted) and Git can't decide.

text
<<<<<<< HEAD
decimal discount = 0.10m;
=======
decimal discount = GetDiscount(customer);
>>>>>>> feature/discounts

Steps:

  1. git status — lists conflicted files.
  2. Edit each file: keep one side, both, or write a new combination; remove the markers.
  3. Build and run tests.
  4. git add <file> then git commit (merge) or git rebase --continue (rebase).
  5. Changed your mind: git merge --abort / git rebase --abort.

Reduce conflicts: small PRs, merge main into long branches often, agree formatting (.editorconfig, Prettier), avoid giant files everyone edits.