← Git from Scratch Lesson 11 of 17 · 10 XP

Merging diverged branches: the merge commit

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

If new commits have appeared in both main and feature, the history has diverged. A fast-forward is impossible, so git creates a special merge commit with two parents:

          C ── D          ← feature
         ╱      ╲
A ── B ──── E ── M        ← main   (M is the merge commit)
git switch main
git merge feature
# Merge made by the 'ort' strategy.

If the branches changed different files or different parts of the same file, git combines the changes by itself. The default message of a merge commit is Merge branch 'feature'.

On the graph a merge commit is drawn as a hollow circle, with two lines coming into it.

Task. While you were working in feature, a commit also appeared in main. Merge feature into main so that you get a merge commit.

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.