Git Merge (original) (raw)

Last Updated : 9 May, 2026

Git Merge combines changes from different branches into a single branch, integrating work while preserving history. It helps unify development without losing progress.

Working

Using the diagrams below, we will see how git merge works what the repository looks like before the merge and how Git creates a new merge commit to combine histories.

Before Merge

gitmerge

This image shows the state of the repository before the merge takes place.

**Elements

**Interpretation

After Merge

git after merge

Git - Merge

This image shows what happens after executing a git merge.

**Elements

**Interpretation

Types of Merging in Git

Git supports several types of merging. The two most common types are:

1. Fast-forward merging

Occurs when Git advances the current branch pointer to the latest commit without creating a merge commit.

git forwarded merging.

Git - Merge

2. Three-way merging

Occurs when branches have diverged, so Git creates a new merge commit by combining their changes.

git three-way merging

Git - Merge

**Note: Git also supports recursive and octopus merging, where recursive is the default strategy for complex histories and octopus merge combines multiple branches in a single commit.

Steps to Perform Git Merge

To ensure smooth merging, follow these steps:

Step 1: Switch to the Target Branch

git checkout

Step 2: Pull the Latest Changes

git pull origin

Step 3: Merge the feature Branch

git merge

If conflicts occur, resolve them manually and then commit.

git-merge-dev

Step 4: Test the Merged Code

Verify that the application works correctly after merging.

Step 5: Push the change

git push origin

Git Merge Vs Rebase

Git merge combines branch histories with a merge commit, while rebase rewrites commits to create a linear history.

git_merge_vs_rebase

Git Merge vs Git Rebase

Git Merge Git Rebase
Combines changes from one branch into another with a merge commit. Applies commits from one branch onto another by rewriting history.
Preserves the complete commit history. Creates a linear history by removing merge commits.
Useful for integrating feature branches. Ideal for a clean, simplified project history.
Does not alter existing commits. Rewrites commit hashes and order.