What is a fast-forward merge in Git?

When the branch you merge already contains all of your branch's commits, git simply moves your branch label forward to its latest commit. No merge commit is needed. That's a fast-forward.

Step by step

  1. Work on a branch:

    $ git switch -c dark-mode
  2. Commit there, then go back:

    $ git switch main
  3. Merge it. If main didn't move meanwhile, it fast-forwards:

    $ git merge dark-mode

If both branches have new commits, git can't fast-forward: it creates a merge commit with two parents instead. Force one anyway with git merge --no-ff.

Try it in the interactive sandbox →Practice “Merge” with a real repository and teammates, right in your browser.

Related guides