Script Valley
Git and GitHub Complete Course: From Beginner to Advanced
Branching, Merging, and Resolving ConflictsLesson 2.4

Resolving Merge Conflicts

merge conflict, conflict markers, git mergetool, resolving conflicts, git add after conflict, abort merge

Resolving Merge Conflicts

A merge conflict occurs when two branches make different changes to the same lines in a file, and Git cannot automatically decide which version to keep. Conflicts must be resolved manually before the merge can complete.

When Conflicts Happen

Git will stop the merge and mark the conflicting files. Running git status shows files listed under "Unmerged paths." Open these files in your editor to see the conflict markers.

Reading Conflict Markers

Git inserts conflict markers into the file:

<<<<<<< HEAD
This is the version from your current branch.
=======
This is the version from the branch being merged in.
>>>>>>> feature/user-login

Everything between <<<<<<< HEAD and ======= is your current branch's version. Everything between ======= and >>>>>>> is the incoming branch's version.

Resolving the Conflict

Edit the file to keep whichever content is correct — or combine both versions as appropriate. Remove all conflict markers. Then stage and commit:

git add conflicted-file.txt
git commit -m "Resolve merge conflict in conflicted-file.txt"

Aborting a Merge

If you are not ready to resolve conflicts, abort the merge and return to the state before it started:

git merge --abort

Using a visual merge tool like VS Code, IntelliJ, or git mergetool makes conflict resolution much easier by showing a three-panel view.

Up next

Rebasing Branches

Sign in to track progress