Sponsored
Ad slot is loading...

Git Merge Conflict Resolution

Guide to resolving git merge conflicts. Conflict markers, resolution strategies, tools, step-by-step process. Fix conflicts quickly.

Conflict Markers

<<<<<<< HEAD
Current branch changes (yours)
=======
Incoming branch changes (their)
>>>>>>> feature-branch

Resolution Strategies

Accept Current: Keep your changes, discard incoming
git checkout --ours
Accept Incoming: Keep incoming changes, discard yours
git checkout --theirs
Accept Both: Keep both changes (combine)
git merge-file with -p
Manual Resolution: Edit file to resolve conflicts
Edit file directly

Resolution Tools

VS Code: Click Accept Current/Incoming/Both in editor
git mergetool: Opens visual merge tool configured
IntelliJ IDEA: Three-way merge view in IDE
Meld: Visual diff and merge tool (Linux)

Step-by-Step Resolution

1. Identify conflict files: git status
2. Open file with conflict markers
3. Understand both versions (<<<<<<< vs >>>>>>>)
4. Choose resolution strategy
5. Remove conflict markers from file
6. Save resolved file
7. Stage resolved file: git add filename
8. Continue merge: git merge --continue
9. Commit: git commit (or auto-commit)

Common Conflict Types

Same line modified in both branches
File deleted in one branch, modified in other
Binary files conflicting
Renamed files causing conflicts
Different whitespace/indentation

Prevention Tips

Pull latest before starting work
Communicate with team about changes
Small frequent commits reduce conflicts
Review changes before merging
Use branches for features, not direct main
Test after resolving conflicts

Example Resolution

Before: <<<<<<< HEAD<br/>const x = 1<br/>=======<br/>const x = 2<br/>>>>>>>> branch<br/>After: const x = 1 // or 2, or combined value. Remove all markers and separators. Keep desired code only.
Sponsored
Ad slot is loading...