Merging is the process of integrating independent lines of development into a unified branch. When you run git merge, Git analyzes the commit graph topology and automatically selects the optimal merge strategy: Fast-Forward or Three-Way Recursive Merge.
A Fast-Forward merge occurs when the target branch (e.g. main) has received NO new commits since you branched off it. In this scenario, there are no divergent changes to reconcile.
To merge, Git doesn't need to create a new merge commit. It simply moves (fast-forwards) the main branch pointer forward to point to the latest commit of your feature branch!
# Step 1: Switch to the branch you want to merge INTO
$ git switch main
# Step 2: Merge the feature branch
$ git merge feature/login
Updating 4a1b2c..8d9e0f
Fast-forward
src/login.js | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
--no-ff)Many production teams prefer to maintain a record of feature branch lifecycles in the commit graph. You can force Git to create a dedicated merge commit even when a fast-forward is possible:
$ git merge --no-ff feature/login -m "merge: integrate feature/login"
A Three-Way Merge occurs when both branches have diverged—i.e., new commits were added to main while you were working on feature/login.
Git cannot simply fast-forward the pointer. Instead, Git's merge engine (the modern ort strategy) performs a 3-way calculation using three snapshots:
main.feature/login.Git compares the changes made on both branches relative to the common ancestor. If the changes occurred in different files or non-overlapping lines of code, Git automatically merges them and creates a brand-new Merge Commit with two parent commits!
$ git merge feature/login
Merge made by the 'ort' strategy.
auth.js | 12 ++++++++++++
1 file changed, 12 insertions(+)
Question: "What makes a merge commit special in Git?"
Answer: "A standard commit has exactly one parent commit. A merge commit created by a 3-way merge has two (or more) parent commits, documenting the exact historical point where two independent branches converged."
Strengthen your version control mastery by studying these connected classes:
Step-by-step conflict resolution workflow using diff markers and graphical tools.
Compare merge commits with rebased linear commit streams.
Compare GitHub's Merge Commit, Squash & Merge, and Rebase & Merge buttons.
Learn how branch pointers diverge and converge in the Directed Acyclic Graph.
Advance your software engineering skills with the next topic in our synchronized curriculum.
Continue to Merge Conflicts → Previous: ← git switch & checkout | Full Syllabus