>_ IzzyLab

Hands-on task

This task is step 16 of the course “Everyday Git”

Resolve a merge conflict

medium~7 min

In /root/repo, the file greeting.txt on branch main contains the line hey, while on branch other the same line is changed to goodbye. Both branches edit the same line, so the merge will produce a conflict.

While on main, merge the other branch, resolve the conflict so that greeting.txt contains exactly one line reconciled (without conflict markers), and finish the merge with a commit. As a result, HEAD on main should become a merge commit (with two parents), and the repository should exit the merging state.

The conflicted file is handy to edit in the Editor tab: it highlights both versions and the markers.

What you'll practise:
  • git merge
  • conflict resolution
  • merge commit
  • git add
  • git commit

Topic breakdown

When two branches edit the same line of a file, an automatic merge is impossible — git stops and inserts conflict markers (<<<<<<<, =======, >>>>>>>) into the file, separating your version from theirs. Resolving the conflict means manually bringing the file to the desired result with the markers removed, after which the file is marked resolved via git add. The finishing commit joins the histories of both branches into a single merge commit with two parents and takes the repository out of the merging state (.git/MERGE_HEAD disappears).

What's checked

  1. greeting.txt brought to the required form
  2. HEAD is a merge commit with two parents
  3. the merge was finished with a commit

What it looks like