# Resolving Merge Conflicts

> When Git pauses a merge because files overlap, and how to safely resolve the conflict markers.

Subject: Version Control | Lesson 12 of 29 | 6 min read
Interactive lesson: https://codewithanimation.in/git/resolving-conflicts
Previous: [Fast-Forward vs 3-Way Merges](https://codewithanimation.in/git/fast-forward-vs-3-way.md) | Next: [What is a Remote?](https://codewithanimation.in/git/what-is-a-remote.md)

## Why Git Halts

A **merge conflict** occurs when you attempt to merge two branches, but Git finds that the *exact same part of the same file* was modified differently in both branches.

Because Git cannot definitively know which developer's changes are the 'correct' ones to keep, it halts the merge process and asks for a human to review the changes.

## Why it matters

In web development teams, you frequently have multiple developers working on shared files simultaneouslyâ€”such as a common `index.html` or a global `styles.css` file.

Understanding how to correctly resolve conflicts is crucial. If done incorrectly, you might accidentally overwrite a teammate's hard work, introduce severe syntax errors, or break the application build.

## How it works (The Markers)

When Git pauses the merge, it modifies the conflicting files by injecting standard conflict-resolution markers: `<<<<<<< HEAD` (start of your current code), `=======` (the divider), and `>>>>>>> branch-name` (end of incoming code).

To resolve it, you must manually edit the file to keep the code you want, and completely delete all the Git markers.

## Common mistake: Forgetting to delete markers

The biggest mistake beginners make is forgetting to delete the `<<<<<<<`, `=======`, and `>>>>>>>` markers after picking the code they want.

If these markers are left in a JavaScript, CSS, or HTML file, it will cause fatal syntax errors and crash the application.

## Tip: Use your editor's built-in tools

A merge conflict is NOT an error. Adopt the mental model that Git is just safely asking a human for help because it isn't smart enough to guess.

Always use a modern code editor (like VS Code). It detects these markers and provides floating buttons to 'Accept Current' or 'Accept Incoming', which safely deletes the markers for you.

## Try it: Resolve a conflicting change

Choose the content to keep, stage the resolution and complete the simulated merge.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/git/resolving-conflicts

## Check yourself

### Question 1

What is the purpose of the `=======` marker in a file with a Git merge conflict?

- A. It marks the very end of the file where the conflict occurred.
- B. It indicates that the code above and below are perfectly identical.
- C. It separates the changes from the current branch and the incoming branch.
- D. It is a syntax error automatically generated by HTML.

Correct answer: C

Git uses the `=======` marker as a dividing line to separate the conflicting changes from `HEAD` (the branch you were on) and the incoming branch you are trying to merge.

- Why not A: That is what the `>>>>>>>` marker is for.
- Why not B: If they were identical, Git would have merged them automatically!
- Why not D: It's generated by Git, not HTML.

### Question 2

After manually editing a file to resolve a merge conflict and removing all the conflict markers, what is the exact next step you must take?

- A. Run `git merge --continue` immediately.
- B. Run `git add <file>` to stage it and mark it as resolved.
- C. Run `git status --resolved`.
- D. Push the file directly to GitHub to save it.

Correct answer: B

Staging the file with `git add` is how you explicitly tell Git that the conflict for that specific file has been successfully resolved. Once all files are staged, you can commit.

- Why not A: You must stage the files first.
- Why not C: This command doesn't exist.
- Why not D: You have to commit the merge locally first.

### Question 3

Why does Git pause and halt the merge process when it encounters a merge conflict?

- A. Because your Git software is outdated and needs to be updated.
- B. Because the remote GitHub repository rejected the code.
- C. Because you modified the same part of a file differently in both branches and Git wants you to make the human decision.
- D. Because your network connection dropped during the merge.

Correct answer: C

Git is safe; it will not guess which developer's code should take precedence when the exact same part of a file has conflicting changes. It pauses the merge to let a human resolve it.

- Why not A: Merge conflicts happen on all versions of Git.
- Why not B: Merge conflicts happen locally before pushing.
- Why not D: Local merging doesn't require a network connection.

## Remember this

- Conflicts happen when lines overlap. Git halts to ask for your help.
- The markers are `<<<<<<<`, `=======`, and `>>>>>>>`.
- Use VS Code's 'Accept Current' / 'Accept Incoming' to safely resolve and delete the markers.
