Overview
Merge conflicts occur when Git cannot automatically merge changes from different branches. GitHub Desktop provides an intuitive interface to help you resolve conflicts and complete merges successfully.Conflict Detection
Automatically detect conflicts when merging or rebasing
Visual Resolution
See conflicted sections side-by-side with clear markers
Manual Resolution
Choose “ours”, “theirs”, or edit manually
File-Level Actions
Resolve entire files with one click when appropriate
Understanding Merge Conflicts
What Causes Conflicts?
Conflicts happen when:- Two branches modify the same lines in a file
- One branch modifies a file while another deletes it
- Two branches create files with the same name
- Binary files are modified in different ways
Types of Conflicts
Content Conflicts
Content Conflicts
Both branches modified the same lines:You must choose which version to keep or combine them.
Modify/Delete Conflicts
Modify/Delete Conflicts
One branch modified a file while another deleted it:
- Keep the file: Use the modified version
- Delete the file: Accept the deletion
Rename Conflicts
Rename Conflicts
Both branches renamed the same file differently:
- Choose which name to use
- Or rename to a new name entirely
Binary Conflicts
Binary Conflicts
Images or other binary files modified on both branches:
- Choose one version (cannot merge binary files)
- Or replace with a new file
Detecting Conflicts
During Merge
When merging branches:During Rebase
When rebasing:During Cherry-Pick
When cherry-picking commits:- GitHub Desktop highlights conflicts immediately
- Shows the commit being applied
- Lists files with conflicts
Resolving Conflicts in GitHub Desktop
Conflict Resolution Interface
When conflicts occur, the Changes tab shows: Conflicted Files Section- Red warning icon
- List of files with conflicts
- “Resolve in [editor]” button
- Manual resolution options
Step-by-Step Resolution
Choose Resolution Method
Select how to resolve:
- Use Ours: Keep your current branch’s changes
- Use Theirs: Accept the incoming branch’s changes
- Open in Editor: Manually edit to combine or modify
Manual Resolution in Editor
For complex conflicts, edit files directly:Edit the File
- Remove conflict markers
- Keep, combine, or rewrite the conflicted sections
- Save the file
Most code editors (VS Code, Sublime Text, etc.) provide syntax highlighting and quick actions for merge conflicts.
Conflict Resolution Implementation
Manual Conflict Resolution
GitHub Desktop supports choosing “ours” or “theirs” for entire files:Modify/Delete Conflict Resolution
When one branch modifies and another deletes:Completing Merge After Conflicts
Merge Commit Message
GitHub Desktop automatically generates merge commit messages:- Source and target branches
- List of conflicted files (as comments)
- Can be edited before committing
Cleanup Process
GitHub Desktop uses
--cleanup=strip to remove Git’s default comment lines from the merge commit message.Aborting Merge/Rebase
If you want to cancel the operation:Abort Merge
Abort Rebase
Preventing Merge Conflicts
Best Practices
Communicate
Coordinate with team members about who’s working on which files
Pull Frequently
Regularly update your branch from the base branch
Small Changes
Make smaller, more focused commits that are easier to merge
Merge Often
Integrate changes frequently instead of letting branches diverge
Proactive Strategies
-
Update from Main Regularly
Keep your feature branch synchronized with the base branch
-
Create Focused Branches
- Work on one feature or fix per branch
- Avoid modifying too many files
- Keep branches short-lived
-
Use Pull Requests
- Review changes before merging
- Get early feedback on potential conflicts
- Use draft PRs for work in progress
-
Coordinate File Ownership
- Establish file ownership conventions
- Communicate before modifying shared files
- Use code review to catch potential conflicts early
Advanced Conflict Scenarios
Multiple Sequential Conflicts (Rebase)
During a rebase, you may encounter conflicts in multiple commits:Submodule Conflicts
When submodules conflict:- GitHub Desktop shows the submodule as conflicted
- You must resolve by choosing which submodule commit to use
- Or update the submodule to a new commit that works for both branches
.gitattributes and Line Endings
Line ending conflicts can be prevented:.gitattributes
.gitattributes ensures consistent line endings across platforms.
Conflict Resolution Tools
External Merge Tools
Configure external tools for complex conflicts: Popular Merge Tools:- Visual Studio Code
- Beyond Compare
- KDiff3
- P4Merge
- Meld
- Right-click conflicted file
- Select Open in external merge tool
Viewing Conflict History
After resolving conflicts:- Switch to History tab
- Find the merge commit
- Review what conflicts existed
- See how they were resolved
Troubleshooting
Cannot Complete Merge
Cannot Complete Merge
If the merge won’t complete:
- Unresolved files: Check all conflicted files are resolved
- Unstaged changes: Ensure resolved files are staged
- Git state: Repository might be in an inconsistent state
- Try: Abort and restart the merge
Conflict Markers Still Present
Conflict Markers Still Present
If you see
<<<<<<< in your code after “resolving”:- You didn’t remove all conflict markers
- Search for
<<<<<<<,=======,>>>>>>>in the file - Remove markers and save
- Stage the file again
Lost Conflict Resolution Work
Lost Conflict Resolution Work
If you accidentally aborted:
- Resolution work is lost (not recoverable)
- Must restart and resolve again
- Consider using
git reflogin terminal if you committed mid-resolution
Binary File Conflicts
Binary File Conflicts
For images, PDFs, or other binary files:
- Cannot merge binary files automatically
- Choose one version or the other
- Or replace with a newly created file
- Consider using Git LFS for large binary files
Too Many Conflicts
Too Many Conflicts
If facing overwhelming conflicts:
- Abort the merge/rebase
- Break changes into smaller chunks
- Update from base branch more frequently
- Consider alternative merge strategies
Tips for Resolving Complex Conflicts
- Understand Both Changes: Read the code from both branches carefully
- Test After Resolution: Always test that the merged code works
- Consult Original Authors: Ask teammates if you’re unsure about their changes
- Use Git History: Check
git logto understand why changes were made - Resolve Incrementally: For multiple conflicts, resolve one at a time
- Document Decisions: Add comments explaining non-obvious resolutions