Conflicts are honesty
When two branches change the same lines, git stops and asks you. Read the markers, choose, and finish a real merge.
A merge conflict feels like something broke. Nothing did. Git found two changes to the same lines on two branches, and it refuses to guess which one you meant. That refusal is the safest thing git does all day.
Git merges line by line. Lines that only one side changed are taken automatically. Git stops only when both sides changed the same stretch, or neighbouring lines with nothing unchanged between them. Then it writes both versions into the file between markers:
<<<<<<< HEAD
apples
=======
pears
>>>>>>> snack
The part above ======= is your current branch (HEAD). The part below is the branch you’re merging in. You edit the file to say what it should say, delete the markers, git add the file to mark it resolved, and commit.
Resolve a real one
On main someone replaced “leaves” with “apples”. On snack someone replaced the same line with “pears”. Merge them and decide.
Main changes line 2 of a file. Your branch changes line 9 of the same file. Will merging conflict?
Git merges by lines, not whole files. Unchanged lines between the two edits act as anchors, so both changes are applied. Conflicts need overlapping or touching changes.
You fixed the file and removed the markers. git commit still refuses. What did you probably forget?
Git tracks conflicted files as unmerged until you git add them. Editing the file isn't enough; adding it tells git the conflict is resolved.
Everything above ran in your browser. Now do it on a real cluster withthe tilt platform. You need Docker, kind and Tilt, about 15 GB of free disk and 8 GB of spare RAM. Setup guide · Can my machine run it?
git init menu && cd menu
printf "bamboo\nleaves\nshoots\n" > menu.txt && git add . && git commit -m menu
git branch snack
sed -i.bak 's/leaves/apples/' menu.txt && git commit -am apples
git switch snack
sed -i.bak 's/leaves/pears/' menu.txt && git commit -am pears
git switch main && git merge snack
cat menu.txtSources
Missions and quizzes above earn their own XP. This marks the lesson done.