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
| Strategy | Description |
|---|---|
| --no-ff | Create merge commit |
| --squash | Combine all commits |
| --rebase | Rebase onto branch |
Mini Practice
- Merge a feature branch
- Handle merge conflicts
- Use --no-ff flag
- 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.