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
Visual Resolution
Manual Resolution
File-Level Actions
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
Modify/Delete Conflicts
Modify/Delete Conflicts
- Keep the file: Use the modified version
- Delete the file: Accept the deletion
Rename Conflicts
Rename Conflicts
- Choose which name to use
- Or rename to a new name entirely
Binary Conflicts
Binary Conflicts
- Choose one version (cannot merge binary files)
- Or replace with a new file
Detecting Conflicts
During Merge
When merging branches:Initiate Merge
Select Branch
Conflict Warning
- Shows number of conflicted files
- Lists affected files
- Stops the merge for resolution
During Rebase
When rebasing:Start Rebase
Conflict Detection
- Rebase pauses at the conflicted commit
- Shows which commit caused the conflict
- Displays conflicted files
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
Identify Conflicted Files
Open Conflict
Choose Resolution Method
- 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
Resolve Each Conflict
Mark as Resolved
Complete Merge
Manual Resolution in Editor
For complex conflicts, edit files directly:Open in Editor
Find Conflict Markers
<<<<<<<, =======, and >>>>>>> markersEdit the File
- Remove conflict markers
- Keep, combine, or rewrite the conflicted sections
- Save the file
Return to GitHub Desktop
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
--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
Click Abort
Confirm
Return to Previous State
Abort Rebase
Click Abort
Confirm
Restore Original State
Preventing Merge Conflicts
Best Practices
Communicate
Pull Frequently
Small Changes
Merge Often
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:Resolve First Conflict
Continue Rebase
Handle Next Conflict
Complete Rebase
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 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
- 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
<<<<<<< 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
- 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
- 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
- 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