</>
Skip to content
Git lessons (19/44)

Git — Merge Branch

Basic Merge

git checkout main
git merge feature-branch

Merge Types

Fast-Forward

# When main hasn't changed
git merge feature
# Simply moves pointer

Three-Way Merge

# When both branches have commits
git merge feature
# Creates merge commit

Merge Conflicts

# Conflicts look like
<<<<<<< HEAD
Current branch content
=======
Branch content being merged
>>>>>>> feature-branch

Resolve Conflicts

# 1. Edit files to resolve
# 2. Mark as resolved
git add .
# 3. Complete merge
git commit -m "Merge feature into main"

Abort Merge

git merge --abort

Merge Strategies

StrategyDescription
--no-ffCreate merge commit
--squashCombine all commits
--rebaseRebase onto branch

Mini Practice

  1. Merge a feature branch
  2. Handle merge conflicts
  3. Use --no-ff flag
  4. Squash merge

Up Next

Continue with Rebase — rebasing branches.

Related Topics

Frequently Asked Questions about Merge Branch

What is Merge Branch in Git?

Merge Branch is a fundamental concept in Git. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Merge Branch?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Merge Branch.

Why is Merge Branch important in Git?

Merge Branch is essential for Git development. Understanding this concept will help you write better code and solve real-world problems more effectively.