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.

DiagramMerge Conflict Resolution Flow

IMAGE PROMPT (replace this block with your generated image):

Flat numbered-step process diagram on white background. Title: Resolving a Git Merge Conflict. Five sequential step boxes connected by down arrows. Step 1 (light red fill): Conflict Occurs โ€” git merge triggers CONFLICT message. Terminal output snippet shown. Step 2 (light amber fill): Run git status โ€” shows Unmerged paths list with conflicted file names in red. Step 3 (light #3A5EFF fill): Open File and Read Markers โ€” shows the three conflict marker blocks in monospace: <<<<<<< HEAD (your version, green highlight), ======= (divider), >>>>>>> feature/branch (incoming, red highlight). Step 4 (light green fill): Edit File โ€” Keep Correct Content โ€” shows the cleaned file with all markers removed, correct final content. Step 5 (solid #3A5EFF fill, white text): Stage and Commit โ€” commands: git add conflicted-file.txt then git commit. Emergency exit branch arrow from Step 1 labeled git merge --abort (red dashed). White background, clean numbered step circles in #3A5EFF.

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

Resolving Merge Conflicts โ€” Branching, Merging, and Resolving Conflicts โ€” Git and GitHub Complete Course: From Beginner to Advanced โ€” Script Valley โ€” Script Valley