What to Do with a Merge Conflict
1. When you encounter a merge conflict, Git will halt the merge process and clearly identify the file(s) that contain conflicting changes. Take careful note of these files—you'll need to resolve each one individually before proceeding. 2. Open the conflicted file in your code editor and locate the conflict markers that Git has automatically inserted:
<<<<<<< HEAD Marks the beginning of your current branch's changes (the branch you're merging into).
======= Acts as a divider, separating your changes from the incoming changes in the other branch.
>>>>>>> branch-name Marks the end of the conflicting section, showing changes from the branch being merged in.
3. Now comes the critical decision: how to resolve the conflict. You have several strategic options depending on your project's needs:
- Manual resolution: Edit the code directly to decide which version to keep, or craft a hybrid solution that combines the best of both approaches. This gives you maximum control but requires careful attention to detail. Always remove the conflict markers (<<<<<<, =======, >>>>>>>) after making your edits—leaving them in will break your code.
- Automated resolution: If you're confident about which version to use wholesale, Git provides efficient commands to accept one side completely. This approach is particularly valuable when working in team environments where you need to make quick, decisive choices:
- git checkout --ours example.html (When you're on the master branch merging a feature branch, --ours preserves the current master branch version, effectively rejecting the incoming changes)
- git checkout --theirs example.html (Conversely, --theirs accepts the incoming feature branch version, overwriting your current branch's version of that file)
- Pro tip: If you're uncertain which option gives you the desired result, test both commands sequentially. Run one, examine the file, then run the other and compare. This eliminates guesswork and saves significant time since you avoid manual editing and marker removal—the commands automatically deliver clean, conflict-free files.
4. Once you've resolved all conflicts, stage your changes with git add, commit them with a descriptive message, and push to your remote repository if needed. Your merge is now complete and your codebase remains stable.
Merge Conflict Resolution Process
Identify Conflicted Files
Git will list all files with conflicts. Take note of each file that needs attention before proceeding with resolution.
Locate Conflict Markers
Open conflicted files and find the HEAD, equals, and branch-name markers that divide the conflicting code sections.
Choose Resolution Strategy
Decide whether to manually edit the code, keep one version entirely, or create a combination of both versions.
Stage and Commit Changes
After resolving conflicts, stage the modified files and commit the merge to complete the process.
HEAD marks the start, equals divides versions, and branch-name marks the end. Always remove these markers after resolving conflicts.
Git Checkout Strategies
| Feature | ours | theirs |
|---|---|---|
| Usage Context | Keep current branch version | Keep incoming branch version |
| Command Example | git checkout --ours file.html | git checkout --theirs file.html |
| Best For | Preserving master branch changes | Accepting feature branch updates |
Manual Editing vs Checkout Commands
Merge Conflict Resolution Checklist
Ensures no conflicts are missed during resolution
Understanding changes helps make informed decisions
Validates approach before applying to all conflicts
Prevents syntax errors in final code
Ensures resolution maintains working application
Completes the merge process properly
Go Beyond Git
Mastering version control is just one piece of building a successful development career. Whether you're looking to advance your current role or transition into tech entirely, our comprehensive coding programs provide the hands-on experience and expert mentorship that today's employers demand.
Available Programming Courses
Web Development Classes NYC
Learn full-stack development through hands-on projects. Build real applications with modern frameworks and industry best practices from expert instructors.
Python Programming Classes NYC
Master Python fundamentals and advanced concepts. Work on practical projects that demonstrate real-world programming skills and problem-solving techniques.
Data Science Classes NYC
Explore data analysis, machine learning, and statistical modeling. Apply data science techniques to solve complex business problems with industry-standard tools.
Our coding bootcamps and classes focus on practical experience with expert instructors guiding you through industry-relevant projects that build your professional portfolio.