Skip to main content
Back to command reference
Branching & Merging

git merge

Combine changes from one branch into your current branch

Practical example

bash
git checkout main
git merge feature-login
# If conflicts: resolve them, then:
git add .
git commit

Command overview & how it works

Takes the commits from a source branch and integrates them into your current branch. When the target branch has not diverged, Git performs a fast-forward merge — it simply moves the branch pointer forward. When branches have diverged, Git creates a merge commit that has two parents, preserving the full history of both branches. If conflicts occur (changes overlap in the same lines), Git pauses with the conflicting files marked. Use git merge --abort to cancel a conflicted merge and return to the pre-merge state. Use git merge --no-ff to force a merge commit even when fast-forward is possible — useful for preserving feature branch context. Use git merge --squash to combine all source branch commits into a single commit on the target branch. Always merge on the receiving branch (e.g., checkout main, then merge feature-login).

Chapter 04 · Branching & Merging

Resolve conflicts and master branch mechanics

Understand 3-way diffs, conflict marker anatomy, and rebasing playbooks in the 97-page offline course — ₹499.

Learn more

Practical tips

  • Always merge on the receiving branch: check out main first, then merge the feature branch into it.
  • Use --no-ff to preserve the feature branch in history, or --squash to fold it into a single commit.
  • If a merge conflicts and you get stuck, git merge --abort returns you to the exact pre-merge state.

Deep-dive guides & tutorials

In-depth walkthroughs and practical scenarios related to git merge

All guides →

Related commands

More from Branching & Merging