git
conflict resolution
version control
duplicate question
git merge

Git conflict markers

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Git conflict markers appear when Git cannot merge two edits automatically and needs you to decide what the final file should contain. They are not part of Git history by themselves; they are temporary text inserted into your working tree so you can resolve the conflict manually.

What the Markers Mean

A typical conflict looks like this:

text
1<<<<<<< HEAD
2console.log("current branch");
3=======
4console.log("incoming branch");
5>>>>>>> feature-branch

The sections mean:

  • '<<<<<<< HEAD starts the version from your current branch'
  • '======= separates the two competing versions'
  • '>>>>>>> feature-branch ends the version from the branch being merged'

Sometimes you may also see a base section:

text
<<<<<<< HEAD
current change
||||||| merged common ancestors original base ======= incoming change >>>>>>> feature-branch ``` That extra base content can help you understand how both sides diverged from the common ancestor. ## Resolve the File by Editing the Final Content Git does not care whether you keep the current version, the incoming version, or a custom combination. It only cares that you remove the markers and leave valid final content in the file. For example, if the correct result is to combine both messages: ```javascript console.log("current branch"); console.log("incoming branch"); ``` After editing the file, mark it resolved: ```bash git add path/to/file.js ``` Then finish the merge or rebase step: ```bash git commit ``` If you are in a rebase, you would usually run: ```bash git rebase --continue ``` If the conflict is actually too messy to resolve confidently, you can abort the operation and regroup instead of forcing a bad merge. For example, `git merge --abort` or `git rebase --abort` can return the repository to the pre-conflict state. That escape hatch is often better than committing a resolution you do not fully understand. ## Use Git to See the Full Context Conflict markers are easier to understand when combined with status output and diff tools. ```bash git status git diff ``` A merge tool can also help: ```bash git mergetool ``` These tools show the current branch, the incoming branch, and sometimes the merge base, which is much safer than trying to reason from the markers alone in a large file. The most important step is to make sure the result is logically correct, not just marker-free. Removing markers without understanding the code often creates a clean merge that is still behaviorally wrong. If you are unsure which side introduced which lines, `git log`, `git blame`, or inspecting the two branch tips directly can provide more context before you edit the file. ## Common Pitfalls - Deleting the markers but accidentally keeping the wrong logic. - Leaving marker text in the file and committing it by mistake. - Forgetting that a conflict during rebase is resolved with `git rebase --continue`, not an ordinary merge commit flow. - Resolving only one conflicted file and assuming the whole operation is done before checking `git status`. - Treating conflict resolution as a text-formatting task instead of verifying the intended program behavior. - Forcing a manual merge when aborting and retrying with better context would be safer. ## Summary - Conflict markers show where Git could not decide between competing edits. - '`<<<<<<<`, `=======`, and `>>>>>>>` separate the current and incoming versions.' - Resolve the conflict by editing the file into its correct final form and removing the markers. - Use `git add` to mark the file resolved, then continue the merge or rebase. - A correct merge is more important than merely getting rid of the marker lines.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.