What is a fast-forward merge, and when does Git use it?
A fast-forward merge happens when the target branch has no new commits of its own, so Git just moves its pointer forward to the other branch's tip. No merge commit is created and history stays a straight line.
Explain it simply
Imagine a queue at an IRCTC counter where you and a friend stand in the same line. Your friend walked ahead and nobody else joined behind you. To catch up you just step forward; nothing needs combining.
If main has not moved since you created feature, then feature simply contains everything in main plus extra commits. Git moves the main label to the same commit as feature. If both branches gained different commits, a real merge commit is needed instead. You can force a merge commit anyway with --no-ff, and refuse anything but a fast-forward with --ff-only.
Example
git switch main
git merge feature
# Updating 4a1c9e2..b83f0d1
# Fast-forward
git merge --no-ff feature # always create a merge commit
git merge --ff-only feature # fail instead of creating oneWhat to say in the interview
"A fast-forward merge occurs when the branch I am merging into is an ancestor of the other branch, so Git only advances the pointer and creates no merge commit. If the branches have diverged, Git makes a three-way merge. --no-ff forces a merge commit to keep the branch visible in history."