Merging Branches
๐ Covered in this chapter:
Fast-Forward Merge ยท Three-Way Merge ยท Merge Commits ยท Deleting Merged Branches
Combine the history of two branches using git merge, understanding fast-forward vs three-way merges.
1Merging Branches โ What You'll Learn
Combine the history of two branches using git merge, understanding fast-forward vs three-way merges.
Here's everything this chapter covers, in the order you'll learn it:
- What merging does
- Fast-forward merges (no divergent history)
- Three-way merges (creates a merge commit)
- Merging a feature branch into main
- Understanding the resulting merge commit
- No-fast-forward merges (--no-ff)
- Verifying the merge result
- Deleting a branch after it's merged
- Merge best practices
- An introduction to merge conflicts (Phase 4, next chapter)
2Working Example
๐ป Example: Merging Branches
Bash
git switch main
git pull origin main
git merge feature/java-tutorial
git branch -d feature/java-tutorial
3Best Practices & Common Pitfalls
๐ก Key things to remember:
- Always pull the latest main before merging your feature branch into it, to reduce the chance of conflicts.
- git branch -d only deletes a branch that's already fully merged โ Git protects you from silently losing unmerged work.
โ Frequently Asked Questions (FAQ)
Q What's the most important thing to understand about merging branches?
Focus on: Fast-Forward Merge ยท Three-Way Merge ยท Merge Commits ยท Deleting Merged Branches. These are the core building blocks this chapter's examples are built around, and they show up repeatedly in later chapters of this course.
Q Is merging branches something I'll use often in real projects?
Yes โ every concept in this chapter reflects a real, everyday part of professional Git and GitHub workflows, not just a theoretical exercise.