Git Merge Strategies: Fast-forward, No-ff, and Squash

Understand git merge strategies: fast-forward, --no-ff, and --squash. Learn when to use each strategy and how they affect your commit history.

Branching

Detailed Explanation

Git Merge Strategies

Git offers several ways to merge branches, each producing a different commit history shape.

Fast-forward Merge (Default)

When the target branch has no new commits since the feature branch was created, git simply moves the pointer forward.

git merge feature/login
# If possible, creates no merge commit

Result: A linear history -- the commits appear as if they were made directly on main.

No Fast-forward (--no-ff)

Forces a merge commit even when fast-forward is possible.

git merge --no-ff feature/login

This preserves the fact that a group of commits came from a feature branch. Many teams require this to maintain clear branch boundaries in history.

Squash Merge

Combines all feature branch commits into a single commit on the target branch.

git merge --squash feature/login
git commit -m "feat: add login functionality"

The feature branch history is lost in the merge, resulting in a very clean single-commit change on the target branch.

Comparison

Strategy Merge Commit Branch History Linearity
Fast-forward No Lost Linear
--no-ff Yes Preserved Branched
--squash No (manual) Lost Linear

Common Team Policies

  • GitHub default: Squash and merge (clean main history)
  • GitLab default: Merge with --no-ff (preserve branch structure)
  • Rebase workflow: Rebase + fast-forward (linear history)

Configuring Defaults

# Always create merge commits
git config --global merge.ff false

# Only allow fast-forward merges
git config --global merge.ff only

Use Case

Choosing a merge strategy is a team-level decision that affects how readable the project history is. Fast-forward is great for solo projects, --no-ff is popular in teams that want to see branch boundaries, and squash merge is the standard for open-source projects that want a clean main branch. Understanding these options helps developers follow their team's workflow and make informed choices about branch management.

Try It — Git Command Reference & Cheat Sheet

Open full tool