Ravindra BagaleCourses & study guides

Chapter 3: Branching, Merge and GitHub PRs

3.6 Resolve a simple conflict

Why. Two branches edited the same lines. Git will not guess.

Tiny example. On main, the README title is # badge API hello. On feature/readme-fix, you change it to # Instagram-style badge API API. Meanwhile someone else (or you on another branch) changed the same line to # badge API menu service. Merging produces a conflict.

Conflict markers look like this:

<<<<<<< HEAD
# badge API menu service
=======
# Instagram-style badge API API
>>>>>>> feature/readme-fix

HEAD is "your current branch." The other side is the branch being merged in. Delete the markers and keep the final correct text.

Steps — create and fix a practice conflict

  1. On main, commit a README line: # badge API hello.
  2. Create feature/a — change that line to # badge API API, commit.
  3. Switch to main again. Create feature/b from main — change the same line to # badge API menu, commit.
  4. Merge feature/a into main (should be clean).
  5. Merge feature/b into main — Git should stop with a conflict.
  6. Open the file, remove <<<<<<<, =======, >>>>>>>, keep one good title.
  7. git add README.md then git commit (Git often opens a merge message — save it).
  8. Confirm git status is clean and git log --oneline --graph -8 shows the join.

What you see after a good fix: no conflict markers left in the file; status clean; history continues.

Ravindra Bagale's Tip

Khup students conflict markers file madhe sodtat aani app break hoto. Merge commit adhi file madhe <<<<<<< search kara — zero matches pahije. Dhyan rakho!

Practice task

Explain in four sentences: what a conflict means, where markers come from, what you delete, and what you run after editing.