Difference between 'git merge --no-ff' and 'git merge --ff-only'

--ff-only: Does Not Create a Merge Commit

git merge --ff-only codex/new-branch

Allows only fast-forward merges: directly moves the current branch pointer without creating a merge commit.

A──B──C

If the two branches have already diverged, the merge will fail.

Suitable for: Maintaining a linear commit history.

--no-ff: Creates a Merge Commit

git merge --no-ff codex/new-branch

Creates a new merge commit even if a fast-forward merge is possible.

A──B────M
    \\  /
     C

Suitable for: Preserving the complete merge history of feature branches.

Summary

  • --ff-only: Merges only if a fast-forward is possible; otherwise, aborts without creating a merge commit.
  • --no-ff: Preserves branch boundaries via merge commits.