Skip to content
New — orchestrate a team of Mel agents from your terminal. Learn more about orchestrating Mel agents
← All guides

Guides · git

How to fix a merge conflict in git

By Lalla Asmaa Alaoui, founder of Mel · Updated

Open each file git marks as conflicted, find the lines between <<<<<<< and >>>>>>>, keep the version you want, and delete the markers. Then run git add on the file and git commit to finish the merge.

A conflict happens when two branches change the same lines, or one branch edits a file the other deleted. Git cannot guess which change is right, so it stops and asks you. Nothing is lost while you decide. The steps below are the same on Mac, Linux and Windows.

Steps

  1. See which files are in conflict.
git status

Conflicted files are listed under "Unmerged paths" as "both modified". For just the names:

git diff --name-only --diff-filter=U
  1. Open a conflicted file and find the markers. Each conflict looks like this:
<<<<<<< HEAD
const timeout = 30;
=======
const timeout = 60;
>>>>>>> feature-branch

The part above ======= is your current branch (HEAD). The part below is the branch you are merging in.

  1. Decide what the code should be. Keep one side, keep both, or write a new line that combines them. Then delete all three marker lines. The result might simply be:
const timeout = 60;

Read the code around the conflict, not only the conflict itself. The right answer often depends on what each branch was trying to do.

  1. Search for leftover markers. One missed marker breaks the build.
git diff --check

This warns about leftover conflict markers and whitespace errors. You can also search with grep -n "<<<<<<<" path/to/file on Mac and Linux, or findstr /n "<<<<<<<" path\to\file in Windows Command Prompt.

  1. Mark the file as resolved.
git add path/to/file

Repeat steps 2 to 5 for every conflicted file.

  1. Build and test. Run your project's tests before you commit. A merge can be free of conflict markers and still break, for example when one branch renamed a function the other branch calls.
  1. Finish the merge.
git commit

Git fills in a merge message for you. Save and close the editor. On newer versions of git, git merge --continue does the same.

Shortcuts and escape hatches

  • Take one side for a whole file. During a merge, git checkout --ours path/to/file keeps your branch's version and git checkout --theirs path/to/file keeps the incoming one. Then git add the file. During a rebase the meaning of ours and theirs is swapped, so check the result before you add it.
  • Start over. git merge --abort puts everything back to how it was before the merge began.
  • Conflicts during a rebase. Resolve the same way, then run git add and git rebase --continue instead of git commit. Use git rebase --abort to give up.
  • Clearer conflict markers. git config --global merge.conflictStyle zdiff3 adds a third section showing the original lines, which makes many conflicts easier to read. It needs git 2.35 or newer; older versions can use diff3.

Avoid the next one

  • Pull or rebase from main often, so your branch never drifts far.
  • Keep branches small and short-lived.
  • Agree on formatting tools, so whitespace changes do not collide.

Doing it with Mel

Every command above works at Mel's prompt. git status and git diff become blocks you can scroll and filter, and file paths in the output become links you can ctrl+click (cmd+click on macOS) to open.

A merge conflict is also a good job for an agent, because the fix needs reading, editing and testing. Press ctrl+enter (cmd+enter on macOS) and write something like: "Resolve the merge conflicts in this repo. For each one, explain what each side changed and which you kept, then run the tests." The agent can read both sides, propose edits and run the test command. With Mel's approvals, each edit and command shows on an approval card before it runs, and every applied edit shows as a diff card.

When the agent is done, open the code review panel with ctrl+shift+= (cmd+shift+= on macOS) and read the final result. Run git commit yourself when you agree with it.

FAQ

What do the <<<<<<<, ======= and >>>>>>> markers mean? They mark one conflict. Lines between <<<<<<< and ======= are your current branch. Lines between ======= and >>>>>>> are the incoming branch. Delete all three marker lines when you resolve it.

How do I cancel a merge with conflicts? Run git merge --abort. Your branch goes back to the state it was in before you started the merge.

How do I keep my version of a file in a conflict? During a merge, run git checkout --ours path/to/file, then git add path/to/file.

Why do I still see conflict errors after editing the file? Git waits until you git add each resolved file. Check git status for files still listed under "Unmerged paths".

Can an AI agent fix merge conflicts? It can propose a resolution and run your tests. You should still read the diff, because only you know which change the team intended.

Facts checked on Oct 25, 2026.

Git is a trademark of its owner. Mel is not affiliated with or endorsed by Git.

Mel – the agentic terminal · openmel.dev. A multi-agent, multi-model AI terminal for Mac, Windows, Linux and VS Code. Free with your own API key.

Lalla Asmaa Alaoui
Written by
Lalla Asmaa Alaoui
Founder & CEO of Mel

Lalla is a hands-on tech founder, agentic infrastructure architect and the vision behind Mel.

Follow on LinkedIn

Get started

Try the agentic terminal.

The Mel terminal is free to download, no account needed. The AI agent is free on your own provider key — 1,500 hosted-AI credits a month on Pro.