Skip to content
jsworkbench.
Learning path
Advanced18 min

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.

Conflict markers
MarkerMeaningWhat you do
<<<<<<<Your side startsRead it
=======The two sides splitChoose or combine
>>>>>>>Their side endsDelete 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.

  1. Step 1

    Commit one version on main

    In the editor, set README.md to exactly: main line

  2. Step 2

    Stage the main line

    The editor text is not in the commit until you add it.

  3. Step 3

    Store the main line

    main now contains exactly those words.

  4. 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

  5. Step 5

    Stage the topic line

    This is the other version of the same line.

  6. Step 6

    Commit the topic line

    readme-topic now disagrees with main.

  7. Step 7

    Change main’s same line again

    Switch to main and set README.md to exactly: main line revised

  8. Step 8

    Stage the revised line

    Main and the topic branch have now both edited README.md.

  9. Step 9

    Commit the revised main line

    The next merge has to choose between two edits of the same line.

  10. Step 10

    Merge and get the conflict

    Git stops. The editor shows both versions between the conflict markers.

  11. Step 11

    Choose the text

    In the editor, delete the markers and leave only: chosen line

  12. Step 12

    Finish the merge

    Stage the file you resolved, then commit. The markers should be gone from git show.

  13. 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.

Follow the steps. Each command step can be placed in the terminal. Edit files in the editor, then stage them.
Supported command reference
  • init
  • add <path> | add .
  • commit -m "message" | commit --amend -m "message"
  • status
  • diff | diff --staged
  • log | log --oneline | log --graph | log --oneline --graph
  • show [ref]
  • branch | branch <name> | branch -d <name>
  • checkout <ref> | checkout -b <name> | switch <name> | switch -c <name>
  • merge <branch>
  • rebase <branch> | rebase -i <branch> | rebase --edit-todo <pick|drop|reword> <hash> [message] | rebase --continue | rebase --abort
  • cherry-pick <ref>
  • reset --soft <ref> | reset --mixed <ref> | reset --hard <ref>
  • revert <ref>
  • stash | stash list | stash pop | stash apply
  • restore <path> | restore --staged <path>
  • remote | remote add <name> <repo-slug>
  • clone <repo-slug> | git clone <repo-slug> | git fork <repo-slug>
  • fetch [remote] | pull [remote] [branch] | push [remote] [branch] | push --force [remote] [branch]
  • blame <path>
  • reflog
  • tag | tag <name> [ref] | tag -d <name>
  • bisect start | bisect good [ref] | bisect bad [ref] | bisect reset
  • config <key> <value> | config --list
  • write <path> <text> (workbench: edit the working tree)
  • issue new "title" | pr new <source> <target> "title" | review "comment" | review --request-changes "comment"

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.

01What do conflict markers mean?
02How do you finish a conflict?

Ready to call this one understood?

Mark this lesson complete to earn 200 XP. You can always revisit it.

Sign in to save progress
Next lesson