🚧 Under construction — VoTechWorks is being built. A free tech program — complimentary, as our commitment to get America working.
voTechWorksGrade 13 · a vocational technology learning center, by urbanicity
newSchoolWorks.com › VoTechWorks › Technology & Design › Web & Software Development › Git Version Control for Web & Software Development › Lesson 6
TEC-WEB46-05 · Lesson 6 · 16 clock hours · lab

Resolving Merge Conflicts

Objective. Students identify conflict markers in conflicted files, manually resolve conflicts by editing file content, mark the resolution with git add, and complete the merge with a commit.

⚠ Pending professional review

This lesson, its worked examples and its practice questions has not yet been verified by an industry-certified professional or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.

VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.

What Is a Merge Conflict?

When Git merges two branches, it usually succeeds automatically by combining changes that affect different lines or different files. A merge conflict occurs when both branches have changed the same lines in the same file in incompatible ways. Git cannot decide which version is correct, so it stops the merge and marks the problem spots for you to resolve manually.

Conflicts are a normal part of collaborative development. Knowing how to resolve them cleanly and confidently is a core professional skill.

How Git Signals a Conflict

When you run `git merge <branch-name>` and a conflict exists, Git prints a message such as:

```

Auto-merging style.css

CONFLICT (content): Merge conflict in style.css

Automatic merge failed; fix conflicts and then commit the result.

```

At this point the merge is paused. Your working directory contains the conflicted file with special markers inserted by Git. Running `git status` will show the file listed under Unmerged paths.

Reading Conflict Markers

Open the conflicted file and you will see a block like this:

```

<<<<<<< HEAD

body { background-color: #ffffff; }

=======

body { background-color: #1a1a2e; }

>>>>>>> feature/dark-theme

```

The three marker lines divide the conflict zone into two sections:

| Marker | Meaning |

|---|---|

| `<<<<<<< HEAD` | Start of your current branch's version |

| `=======` | Divider between the two versions |

| `>>>>>>> branch-name` | End of the incoming branch's version |

Everything between `<<<<<<< HEAD` and `=======` is what your branch says. Everything between `=======` and `>>>>>>> branch-name` is what the incoming branch says.

Resolving the Conflict

Step 1 – Decide on the correct content. You have three options:

The right choice depends on project requirements and team communication. In a professional setting you would discuss with the author of the other branch rather than guess.

Step 2 – Edit the file. Remove the conflict markers (`<<<<<<<`, `=======`, `>>>>>>>`) and leave only the final, correct content. A file with any marker still present is broken code — never commit it.

VS Code with the GitLens extension highlights conflict markers visually and offers one-click buttons to accept the current change, accept the incoming change, or accept both. These shortcuts edit the file for you, but you must still review the result.

Step 3 – Stage the resolved file.

```

git add style.css

```

This tells Git that you have finished resolving that file.

Step 4 – Complete the merge.

```

git commit

```

Git opens your editor with a pre-filled commit message describing the merge. Save and close to finalize. The merge commit now has two parents, recording exactly where the two histories joined.

Step 5 – Verify.

```

git log --graph --oneline

```

You should see a merge commit (with two parent lines in the graph) at the top of the log. Running `git diff` on the result should show no remaining conflict markers.

Professional Habits Around Conflict Resolution

Aborting a Merge

If you become confused mid-resolution, you can safely cancel the entire merge and return to the state before you started:

```

git merge --abort

```

This is always safe to run while a merge is paused. Use it freely during practice.

Safety Note

Version control is the safety net for source code. Never force-push or discard a branch without understanding its history. In a team environment, always confirm with your team lead before rewriting shared history. Treat the `main` or `production` branch with the same care you would treat any critical system — one bad merge deployed to a live server can take a site offline.

Key terms8

Merge conflictA situation where Git cannot automatically combine two branches because both have changed the same lines in incompatible ways, requiring manual resolution.
Conflict markerOne of the three special strings Git inserts into a conflicted file — <<<<<<< HEAD, =======, and >>>>>>> branch-name — to delimit the two competing versions of the content.
HEADA Git reference that points to the most recent commit on the currently checked-out branch; in a conflict marker it labels your local version of the conflicted content.
git merge --abortA Git command that cancels an in-progress merge and restores the working directory to the state it was in before the merge began.
Merge commitA special commit created at the end of a successful merge that has two parent commits, permanently recording where two lines of history were joined.
Unmerged pathGit's term for a file that has a conflict and has not yet been staged with git add; it appears in this state when you run git status during a paused merge.
GitLensA popular VS Code extension that enriches the Git experience with visual conflict highlighting, blame annotations, and one-click conflict resolution buttons.
git log --graph --onelineA Git command that displays the commit history as a compact, text-based graph showing branch and merge structure alongside abbreviated commit hashes and messages.
In class: Instructor creates a prepared repository where two branches have made incompatible edits to the same lines of style.css; students attempt the merge, observe the CONFLICT message, and open the file to identify the <<<<<<<, =======, and >>>>>>> markers. · Students resolve the conflict by deciding which changes to keep (or combining both), remove all markers, save the file, run git add style.css, and complete the merge with git commit; run git log --graph --oneline to confirm the merge commit appears correctly. · Repeat the exercise with a second prepared conflict scenario involving a JavaScript file; this time students write a brief written explanation in their lab log of the reasoning behind their resolution decision, simulating a professional code review note.
Materials: Prepared conflicted repositories (two scenarios provided by instructor), terminal, VS Code with GitLens extension installed, lab log
Check: Repository shows a clean merge commit with no remaining conflict markers (verified by instructor running git diff on the result); lab log reasoning entry present; student answers three oral questions about conflict resolution to 80% accuracy.

Practice check8

Answer each question, then check it. Nothing is recorded; this is your own practice.

Core IT concepts and version control fundamentals
1. When Git cannot automatically merge two branches, what does it do to the conflicted file?
Core IT concepts and version control fundamentals
2. In a conflict marker block, what does the content between <<<<<<< HEAD and ======= represent?
Core IT concepts and version control fundamentals
3. After manually editing a conflicted file to remove all markers and decide on the final content, what is the correct next command?
Core IT concepts and version control fundamentals
4. A developer is halfway through resolving a merge conflict and realizes she does not understand what the incoming branch was trying to accomplish. What is the safest immediate action?
Core IT concepts and version control fundamentals
5. Which git log option produces a text-based graph that clearly shows where merge commits join two lines of history?
Core IT concepts and version control fundamentals
6. A merge commit differs from a regular commit in which important way?
Core IT concepts and version control fundamentals
7. After completing a merge, which command would confirm that no conflict markers remain in the working tree?
Core IT concepts and version control fundamentals
8. Why is it important to test the application after resolving a merge conflict, even when all conflict markers have been removed?
Record this lesson on my transcript. Sign in with your key and enrollment email to record lessons (enroll free if you have no key). This page stays open to read and practise.