Git Fast-Forward Merge: How It Works
Table of Contents
The simplest type of merge is a fast-forward merge. Git moves the base branch's pointer forward instead of creating a merge commit.
All the content from our Boot.dev courses are available for free here on the blog. This one is from the "Merge" chapter of Learn Git. If you want to try the far more immersive version of the course, do check it out!
What Is a Git Fast-Forward Merge?
Say we start with this:
C delete_vscode
/
A - B main
Because delete_vscode has all the commits that main has (and main has no new commits of its own), Git can just move main's pointer forward:
delete_vscode
A - B - C main
No merge commit is created. Git does this automatically when it can.
Try a Fast-Forward Merge
Run the merge yourself and watch how a fast-forward just moves a branch pointer instead of creating a new commit:
This is a common workflow when working with Git on a team:
- Create a branch for a new change
- Make the change
- Merge the branch back into
main - Remove the branch
- Repeat
You delete a merged branch with:
git branch -d branch_name
If the merge can be a fast-forward, Git will do it automatically. If both branches have diverged (both have unique commits), Git creates a merge commit instead. You don't have to choose — Git figures it out.
The general Git merge guide covers merge commits and how to read merge history. If you want the no-extra-merge-commit flavor, read Git Rebase. I prefer rebasing my own feature branches because a linear history is easier to read and reason about. Rebase is based.
Frequently Asked Questions
What is a fast-forward merge in Git?
It is a merge where Git moves the current branch pointer to the other branch's tip without creating a merge commit.
When can Git perform a fast-forward merge?
Git can fast-forward when the current branch is an ancestor of the branch being merged and has no unique commits of its own.
Does a fast-forward merge create a commit?
No. It reuses the existing commits and moves the branch pointer forward.
Does Git fast-forward automatically?
Yes. If the current branch has no unique commits and can move directly to the other branch's tip, Git fast-forwards automatically.
