MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Merging Branches: Fast-Forward vs Three-Way Merges (git merge)0%
Study Materials
Git & GitHub BasicsProgress 0%
1.1What is Version Control? (Local, Centralized vs Distributed VCS)1.2Why Git? History, Architecture & Core Benefits1.3The Three Trees: Working Directory, Staging Area & Git Repository1.4Installing Git and Initial Configuration (git config user.name / email)
4.1Git Branching Mechanics: Pointers, HEAD, and git branch4.2Switching Branches with git switch and git checkout -b4.3Merging Branches: Fast-Forward vs Three-Way Merges (git merge)4.4Resolving Merge Conflicts Step-by-Step with Conflict Markers
HomeTutorialsGit & GitHub BasicsMerging Branches: Fast-Forward vs Three-Way Merges (git merge)
Resolving Merge Conflicts Step-by-Step with Conflict Markers

Merging Branches: Fast-Forward vs Three-Way Merges (git merge)

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

Once work on an isolated feature branch is completed and tested, it must be integrated back into the main project trunk. The process of combining disparate lines of development is called merging (git merge).


1. How Merging Works

To merge branch B into branch A:

  1. 1
    You must first switch into the receiving branch (A).
  2. 2
    Run git merge B.
1# 1. Switch to destination branch
2git switch main
3 
4# 2. Merge the feature branch into main
5git merge feature-login

Depending on the commit history structure, Git automatically chooses between two merging strategies: Fast-Forward Merge or Three-Way Merge.


2. Strategy 1: Fast-Forward Merge

A Fast-Forward merge occurs when there is a direct linear path from the current branch tip to the incoming feature branch tip. In other words, no new commits were made on main while the feature branch was being developed!

1Before Fast-Forward Merge:
2(C1) <--- (C2) [main, HEAD]
3 \
4 (C3) <--- (C4) [feature-login]
5 
6Command: git switch main && git merge feature-login
7 
8After Fast-Forward Merge:
9(C1) <--- (C2) <--- (C3) <--- (C4) [feature-login, main, HEAD]

Key Properties of Fast-Forward:

  • No merge commit is created.
  • Git simply moves the [main] pointer forward along the commit chain to C4.
  • Fast, clean, and creates zero overhead.

Forcing a Merge Commit (--no-ff):

Some teams prefer to preserve explicit historical evidence that a branch existed:

1git merge --no-ff feature-login

3. Strategy 2: Three-Way Merge (Recursive / Ort)

A Three-Way Merge occurs when both branches have diverged: commits were made on main AND commits were made on feature-login at the same time:

1Diverged History Before Merge:
2 (C3) <--- (C4) [feature-login]
3 /
4(C1) <--- (C2) [Common Ancestor Base]
5 \
6 (C5) <--- (C6) [main, HEAD]

Why is it called "Three-Way"?

Git uses three distinct snapshots to calculate the merged result:

  1. 1
    The Common Ancestor Commit (C2): The point where the two branches split.
  2. 2
    The Current Branch Tip (C6 - main).
  3. 3
    The Incoming Branch Tip (C4 - feature-login).

By comparing both branch tips against their common base, Git can automatically deduce what each developer intended to change:

  • If a line was changed only in feature-login and untouched on main, Git applies the feature change.
  • If a line was changed only on main and untouched in feature-login, Git preserves the main change.
1After Three-Way Merge:
2 (C3) <--- (C4) [feature-login]
3 / \
4(C1) <--- (C2) (C7) [Merge Commit! main, HEAD]
5 \ /
6 (C5) <--- (C6)

Git generates a brand new Merge Commit (C7) that uniquely has two parents (C4 and C6).


4. Summary: Merge Types Comparison

AspectFast-Forward MergeThree-Way Merge (ort/recursive)
Branch TopologyLinear (no divergence)Divergent (both branches advanced)
New Commit Created?No (pointer moves forward)Yes (a dedicated merge commit with 2 parents)
Commit MessageReuses existing feature commitAutomatically prompts for merge commit message
Conflict PotentialLow / NonePossible if same lines were edited concurrently

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What must you do before running git merge feature-payment?
Question 2
When does Git perform a Fast-Forward merge?
Question 3
What unique property distinguishes a Merge Commit resulting from a three-way merge?
Question 4
Which flag forces Git to generate a dedicated merge commit even if a fast-forward merge was possible?
Question 5
In a three-way merge, which three snapshots are evaluated to determine the merge result?
Next Lesson

Resolving Merge Conflicts Step-by-Step with Conflict Markers

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Switching Branches with git switch and git checkout -bResolving Merge Conflicts Step-by-Step with Conflict Markers

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master Git & GitHub Basics with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext