Merge conflicts
Understand the idea
A conflict means both sides edited the same lines. The markers are the file asking you to choose.
The idea
A happens when both sides changed the same lines since their common parent. The file gains conflict markers. The merge or rebase is unfinished until you write the text you actually want, git add the file, and commit. Leaving the markers in stores the argument as if it were the program.
What changes
Use Create a real conflict on this page. main and topic both edit README.md. git merge topic stops. The holds both versions between the markers. The index does not contain a clean snapshot yet. After you write the chosen line, add, and commit, the merge commit's snapshot has only that line.
| Marker | Meaning | What you do |
|---|---|---|
| <<<<<<< | Your side starts | Read it |
| ======= | The two sides split | Choose or combine |
| >>>>>>> | Their side ends | Delete every marker |
The command
Click the conflict button. Open the file with the markers, write README.md the line you want, then git add README.md and git commit -m "resolve the readme". The same markers appear if rebase tries to replay a change onto a line main already rewrote. Finish that one with git rebase --continue.
The mistake
Check your graph
The merge commit has two parents, and git show of README.md is the line you wrote. Search the file for the marker text. It should be gone.
Your repository
Load the conflict exercise, edit the file until the markers are gone, then add and commit.
Step 1
Commit one version on main
In the editor, set README.md to exactly: main line
Step 2
Stage the main line
The editor text is not in the commit until you add it.
Step 3
Store the main line
main now contains exactly those words.
Step 4
Edit the same line on a branch
Create the branch. If it exists, run git switch readme-topic. Then set README.md to exactly: topic line
Step 5
Stage the topic line
This is the other version of the same line.
Step 6
Commit the topic line
readme-topic now disagrees with main.
Step 7
Change main’s same line again
Switch to main and set README.md to exactly: main line revised
Step 8
Stage the revised line
Main and the topic branch have now both edited README.md.
Step 9
Commit the revised main line
The next merge has to choose between two edits of the same line.
Step 10
Merge and get the conflict
Git stops. The editor shows both versions between the conflict markers.
Step 11
Choose the text
In the editor, delete the markers and leave only: chosen line
Step 12
Finish the merge
Stage the file you resolved, then commit. The markers should be gone from git show.
Step 13
Record the choice
This commit has two parents and the text you kept.
The editor edits the working tree. Start a repository and the files appear here.
Commit graph
No commits yet. git init creates the first one.
Quiz
A quick check for understanding. Retry as often as you like; your learning path stays open.
Ready to call this one understood?
Mark this lesson complete to earn 200 XP. You can always revisit it.