2.2 Merge and Conflicts
A merge brings changes from one branch into another. A common workflow is: finish work on a feature branch, then merge it back into main.
Basic merge flow
git switch main
git merge feature/searchIf Git can automatically combine both sides, the merge completes immediately.
What is a merge conflict?
A merge conflict happens when Git cannot automatically decide what to keep. The most common case is when two branches edit the same area of the same file differently.
A concrete conflict example
Suppose README.md originally contains one line:
Title: LeafletOn main, you change it to:
Title: Leaflet course homeYour teammate changes the same line on feature/home-title:
Title: Leaflet interactive learning platformWhen you run:
git switch main
git merge feature/home-titleGit sees that the same line changed differently on both sides, so it writes conflict markers into the file:
<<<<<<< HEAD
Title: Leaflet course home
=======
Title: Leaflet interactive learning platform
>>>>>>> feature/home-titleResolving a conflict is not just deleting markers. You decide what the final file should contain. After editing, run:
git add conflicted-file.md
git commitOne reasonable resolution
If both sides contain useful meaning, you can make the final content:
Title: Leaflet interactive course homeThen run:
git add README.md
git commitThis commit means: "The conflict has been resolved by a human, and the merge is complete."