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).
To merge branch B into branch A:
A).git merge B.Depending on the commit history structure, Git automatically chooses between two merging strategies: Fast-Forward Merge or Three-Way 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!
[main] pointer forward along the commit chain to C4.--no-ff):Some teams prefer to preserve explicit historical evidence that a branch existed:
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:
Git uses three distinct snapshots to calculate the merged result:
C2): The point where the two branches split.C6 - main).C4 - feature-login).By comparing both branch tips against their common base, Git can automatically deduce what each developer intended to change:
feature-login and untouched on main, Git applies the feature change.main and untouched in feature-login, Git preserves the main change.Git generates a brand new Merge Commit (C7) that uniquely has two parents (C4 and C6).
| Aspect | Fast-Forward Merge | Three-Way Merge (ort/recursive) |
|---|---|---|
| Branch Topology | Linear (no divergence) | Divergent (both branches advanced) |
| New Commit Created? | No (pointer moves forward) | Yes (a dedicated merge commit with 2 parents) |
| Commit Message | Reuses existing feature commit | Automatically prompts for merge commit message |
| Conflict Potential | Low / None | Possible if same lines were edited concurrently |
git merge feature-payment?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.