git merge
Combine changes from one branch into your current branch
Practical example
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).
Resolve conflicts and master branch mechanics
Understand 3-way diffs, conflict marker anatomy, and rebasing playbooks in the 97-page offline course — ₹499.
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
- Guide
Git Branching Strategies: Git Flow vs Trunk-Based Development
Compare the most popular branching models and learn when to use merge, rebase, and squash for a clean project history.
8 min readRead guide - Guide
Git Rebase vs Merge: When to Use Each
A clear breakdown of the trade-offs between rebasing and merging, with examples of when each approach makes sense.
5 min readRead guide - Guide
Resolving Git Merge Conflicts: A Practical Guide
Conflicts are inevitable. Learn how to read conflict markers, resolve them systematically, and use tools to make merging painless.
6 min readRead guide
Related commands
More from Branching & Merging