Skip to content
Justice Tech School

Fast-forward and Merge Commits

If main has not moved, a merge just fast-forwards. --no-ff always creates a merge commit, recording that a branch existed.

Example
echo one > a.txt && git add a.txt && git commit -qm 'first'
git switch -q -c f1 && echo b > b.txt && git add b.txt && git commit -qm 'f1 work'
git switch -q main && git merge -q f1
git log --format=%s | head -2
git switch -q -c f2 && echo c > c.txt && git add c.txt && git commit -qm 'f2 work'
git switch -q main && git merge -q --no-ff -m 'Merge f2' f2
git log --format=%s | head -1

Result

f1 work
first
Merge f2

Exercise

Always create a merge commit.

git merge  f2

Quiz Test

When does Git fast-forward?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.