Git & GitHub Interview Question #39

What is a fast-forward merge?

Remotes, Fetch, Pull, Push, Merge, Conflicts, Rebase & Stash Junior Beginner

Quick Interview Answer

A fast-forward merge is possible when the current branch has no new commits after the point where the other branch diverged. Git can simply move the current branch reference forward to the newer commit.

Detailed Explanation

A fast-forward merge is possible when the current branch has no new commits after the point where the other branch diverged. Git can simply move the current branch reference forward to the newer commit.

No merge commit is required because the history is already linear. Teams may allow fast-forward merges or deliberately require merge commits depending on their history policy.

Code Example

git switch main
git merge feature/login

# Require a merge commit even when fast-forward
# would be possible:
git merge --no-ff feature/login