Lesson 11 of 12 · about 16 minutes · When two branches change the same line: read the markers, decide, add, commit.
⚡ 0 XP
Step 1 of 2
Fixing a conflict
If both branches changed the same line, git cannot know who is right. It stops and asks you. That is a merge conflict — totally normal, it happens to every developer.
Git writes both versions into the file between markers:
<<<<<<< HEAD — your version (the branch you are on) starts
======= — the divider
>>>>>>> price-cut — the other branch's version ends
To fix it:
cat menu.txt to read both versions.
Write the final, correct file (no markers left!). Here we use echo "…" > menu.txt; in real life you would use a code editor.
git add menu.txt to mark it fixed.
git commit -m "Merge price-cut" to finish the merge.
The prompt shows (main|MERGING) until you finish.
🎯 Challenge: Papa says ₹8, Mummy says ₹12 +30 XP
On main the price became Masala chai ₹12; on the price-cut branch it became Masala chai ₹8. Merge price-cut into main — it will conflict. Then:
Read the file with cat menu.txt.
The family agrees on ₹10: make menu.txt exactly Masala chai ₹10.
git add menu.txt and finish with git commit -m "Merge price-cut".
Try twice to unlock the solution (0/2)
terminalCtrl ⏎
A safe practice terminal. Type a command and press Enter. Type help to list commands. Tab completes names, ↑ recalls the last command.
Files · ~ = /home/asha
📁 chai-site/ ← you are here
📄 menu.txt
Git timeline
Checklist
Press Run to check your code.
○
The merge is finished with a merge commit
○
price-cut is merged
○
menu.txt is exactly "Masala chai ₹10"
○
Committed menu has no conflict markers
○
Working tree is clean
Lesson notes (text version)
1. Fixing a conflict
If both branches changed the same line, git cannot know who is right. It stops and asks you. That is a merge conflict — totally normal, it happens to every developer.
Git writes both versions into the file between markers:
<<<<<<< HEAD — your version (the branch you are on) starts
======= — the divider
>>>>>>> price-cut — the other branch's version ends
To fix it:
cat menu.txt to read both versions.
Write the final, correct file (no markers left!). Here we use echo "…" > menu.txt; in real life you would use a code editor.
git add menu.txt to mark it fixed.
git commit -m "Merge price-cut" to finish the merge.
The prompt shows (main|MERGING) until you finish.
Challenge: Papa says ₹8, Mummy says ₹12
On main the price became Masala chai ₹12; on the price-cut branch it became Masala chai ₹8. Merge price-cut into main — it will conflict. Then:
Read the file with cat menu.txt.
The family agrees on ₹10: make menu.txt exactly Masala chai ₹10.
git add menu.txt and finish with git commit -m "Merge price-cut".
2. Tidy up merged branches
Once a branch is merged, its commits live in main, so the branch name is no longer needed. git branch -d snacks deletes the name (not the work!).
Git protects you: if the branch is not merged yet, -d refuses. Tidy repos are happy repos.
Challenge: Delete the merged snacks branch
The snacks branch is already merged into main. Delete it with git branch -d snacks (you should see Deleted branch snacks), then run git branch to see only main left.