How do you resolve a merge conflict in Git?
Identify conflicting files, edit the conflict markers, stage the resolved files, and complete the merge.
GitVersion Control
Overview
A merge conflict happens when two branches change the same lines of a file. Git cannot decide which version to keep, so it marks the conflict and asks you to resolve it manually.
Key Points
- •Conflict markers: `<<<<<<<` is your branch, `=======` is the divider, `>>>>>>>` is the incoming branch.
- •Edit the file to keep the correct content, then remove all three conflict markers.
- •After editing, stage the file with `git add` and then commit.
- •`git status` shows all files with unresolved conflicts.
- •Use `git merge --abort` to cancel the merge and return to the state before it started.
Examples
What a conflict looks like inside a file
text<<<<<<< HEAD (your branch)
const greeting = "Hello, world!";
=======
const greeting = "Hi there!";
>>>>>>> feature/update-greetingDelete the markers and keep the version you want (or combine both).
Step-by-step conflict resolution
bash# 1. See which files are conflicted
git status
# 2. Open and edit each conflicted file remove markers, keep correct code
# 3. Stage the resolved file
git add src/greeting.js
# 4. Complete the merge
git commitRepeat steps 2–3 for every conflicted file before committing.
Abort the merge and go back to where you started
bashgit merge --abortRestores your working tree to its pre-merge state.
Accept one side entirely (theirs or ours)
bash# Accept the incoming (merging) branch version
git checkout --theirs src/config.js
git add src/config.js
# Accept your current branch version
git checkout --ours src/config.js
git add src/config.jsUse when you know one side is entirely correct.
Pro Tip
VS Code, IntelliJ, and most modern editors highlight conflict markers and show "Accept Current / Accept Incoming / Accept Both" buttons. Using a visual tool is much faster than editing markers by hand.