Resolving Merge Conflicts in Git
Prerequisites:
- Branching and Merging in Git

Resolving Merge Conflicts in Git
Merge conflicts occur when Git cannot automatically merge changes from two branches that modify the same part of a file differently. In this blog, we’ll learn how to identify and resolve conflicts effectively.
Table of Contents
- What Causes Merge Conflicts?
- Identifying Merge Conflicts
- Resolving Conflicts Manually
- Using Merge Tools
- Exercise: Resolving a Conflict
What Causes Merge Conflicts?
Merge conflicts happen when:
- Two branches modify the same part of a file differently.
- A branch deletes a file while another modifies it.
Identifying Merge Conflicts
When a conflict occurs, Git marks the conflicting areas in the file like this:
<<<<<<< HEAD
Changes from main
=======
Changes from feature-branch
>>>>>>> feature-branch
Resolving Conflicts Manually
- Open the conflicting file and locate the conflict markers.
- Edit the file to decide which changes to keep.
- Stage the resolved file:
- Commit the resolution:
git add conflicting-file
git commit -m "Resolved merge conflict"
Using Merge Tools
Graphical merge tools like VS Code, IntelliJ, or git mergetool
can simplify conflict resolution:
git mergetool
Exercise
Simulate a merge conflict by modifying the same file in two branches. Resolve the conflict manually or using a merge tool. Run git log --graph
to confirm the merge was successful.
Coming Up Next
In the next part of this series, we’ll explore advanced Git commands like cherry-picking and interactive rebase for fine-grained control over your commit history.
Part 4 of 24 in Git Mastery Series: From Beginner to Expert
All Posts in This Series
1. Introduction to Git: What is Version Control?
2. Initializing a Repository and Making Your First Commit
3. Branching and Merging in Git
4. Resolving Merge Conflicts in Git
5. Advanced Git Commands: Cherry-Picking and Interactive Rebase
6. Git Hooks and Automation: Streamlining Workflows
7. Git Workflows and Best Practices: Streamlining Collaboration
8. Debugging with Git: Bisect and Blame
9. Customizing Git: Aliases and Configuration
10. Mastering Git Diff: Analyzing Changes and Advanced Use Cases
11. Common Git Issues and Solutions: Troubleshooting Like a Pro
12. Understanding Git Internals: How Git Works Under the Hood
13. Mastering Git Submodules: Managing Dependencies and Modular Projects
14. Advanced Git Branch Management: Sorting, Pruning, and Deleting Branches
15. Git Reflog Deep Dive: Recovering Lost Commits and Understanding Git’s Safety Net
16. Disaster Recovery with Git: Restoring Corrupted Repositories and Lost Objects
17. Git and Open Source Contributions: Best Practices for Collaborative Development
18. Git Behind Firewalls and Proxies: Overcoming Connectivity Challenges
19. Git Config Deep Dive: Managing SSH Keys and Multiple SSH Keys with ssh_config
20. Git Tagging Strategies: Versioning Releases Effectively
21. Git Security and Signing Commits: Ensuring Trust and Integrity
22. Git and CI/CD Integration: Automating Workflows for Continuous Delivery
23. Git Patch Management: Sharing Changes Without Pushing
24. Partial Clones and Sparse Checkouts: Optimizing Large Repositories