Merge Conflicts
๐ Covered in this chapter:
Conflict Markers ยท Resolving Conflicts ยท git merge --abort
Resolve merge conflicts confidently by reading conflict markers and choosing (or combining) the correct changes.
1Merge Conflicts โ What You'll Learn
Resolve merge conflicts confidently by reading conflict markers and choosing (or combining) the correct changes.
Here's everything this chapter covers, in the order you'll learn it:
- Why merge conflicts occur
- Reading conflict markers in a file
- Choosing the current branch's change
- Choosing the incoming branch's change
- Combining both changes manually
- Marking a conflict as resolved
- Completing the merge after resolving
- Aborting a merge entirely
- Preventing conflicts through smaller, frequent merges
- Communicating with teammates about conflicting work
2Working Example
๐ป Example: Merge Conflicts
Text
<<<<<<< HEAD
Current branch code
=======
Incoming branch code
>>>>>>> feature-branch
๐ป Continued Example
Bash
git status
git add resolved-file.js
git commit
# Or, to cancel entirely:
git merge --abort
3Best Practices & Common Pitfalls
๐ก Key things to remember:
- Conflict markers (<<<<<<<, =======, >>>>>>>) must be manually deleted after you decide what the final code should look like โ Git won't remove them for you.
- git merge --abort safely cancels a messy merge and returns you to exactly where you were before it started.
โ Frequently Asked Questions (FAQ)
Q What's the most important thing to understand about merge conflicts?
Focus on: Conflict Markers ยท Resolving Conflicts ยท git merge --abort. 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 merge conflicts 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.