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
- On
main, commit a README line:# badge API hello. - Create
feature/a— change that line to# badge API API, commit. - Switch to
mainagain. Createfeature/bfrommain— change the same line to# badge API menu, commit. - Merge
feature/aintomain(should be clean). - Merge
feature/bintomain— Git should stop with a conflict. - Open the file, remove
<<<<<<<,=======,>>>>>>>, keep one good title. git add README.mdthengit commit(Git often opens a merge message — save it).- Confirm
git statusis clean andgit log --oneline --graph -8shows 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.