Video in progress

Strong Junior 🌿 Git

What is the difference between a fast-forward merge and a merge that creates a merge commit?

If main has not moved forward since you created your branch, Git simply moves the main pointer to your last commit, and that is a fast-forward. If both sides have new commits, a new merge commit with two parents is created.

📖 Answer

With a fast-forward there is no new commit, and the history stays a straight line:

before:  main: A---B           feature: A---B---C---D
after:   main: A---B---C---D

If main also has a new commit:

main:    A---B---E
              \
feature:       C---D
after the merge: A---B---E---M  (M's parents: E and D)

Flags to control it:

git merge --ff-only feature   # only if it is a fast-forward, otherwise an error
git merge --no-ff feature     # create a merge commit even if a fast-forward is possible

Some teams use --no-ff on purpose: it leaves a boundary in the history saying "these commits were one feature", and the whole feature is easy to revert with a single git revert -m 1 M.