Resolve a merge conflict
Working with remotes · Article 6 of 9 · 4 min read
Conflicts look scary the first time, but they are just Git asking you to choose.
The short version
A conflict happens when two branches change the same lines. Git cannot guess which version you want, so it stops and marks the file for you to fix.
Details
Git writes both versions into the file between markers: <<<<<<<, ======= and >>>>>>>. You edit the file to the result you want, remove the markers, then stage and commit.
Try it yourself
git switch -c left
echo "left" > clash.txt
git add clash.txt
git commit -m "Left"
git switch main
git switch -c right
echo "right" > clash.txt
git add clash.txt
git commit -m "Right"
git merge left
Git reports a conflict in clash.txt. Open it, keep the line you want, delete the markers, then run:
git add clash.txt
git commit
Explain it to the duck
Why can Git merge most changes on its own but not these?
Tested with: Git 2.51.