FIX · ERROR

"CONFLICT (content):
Merge conflict in..."

Git tried to combine two branches and found both changed the same lines. It will not guess. It stops, marks the spot in your file, and waits for you to decide.

git status<<<<<<<git addgit merge --abort

The short answer

nothing is lost
1

Find it

git status lists the files under "Unmerged paths". Only those need your attention.

2

Choose

Open the file. Keep your side, their side, or write a mix. Then delete the three marker lines.

3

Finish or bail

git add the file, then git commit. Or run git merge --abort to go back to before the merge.

A conflict is not a broken repository. Nothing is lost, and git merge --abort puts everything back as it was before you started the merge.

What it looks like

real Git 2.34.1 output

Both branches changed the same line of f.txt. Between <<<<<<< HEAD and ======= is your current branch. Between ======= and >>>>>>> feat is the branch you are merging in. The steps are described in the GitHub Docs page on resolving conflicts on the command line.

Pick the way out

what you want
you want to
run
result
Keep my version
Edit the file so only your lines remain, delete the three marker lines
Save, then git add FILE and git commit.
Keep their version
Edit the file so only the other branch's lines remain
Same as above. The marker lines must be gone.
Combine both
Write the final text by hand, delete the three marker lines
Same as above. You are the editor here.
Start over
git merge --abort
Back to how things were before the merge. Only works while the merge is unfinished.

Check it worked

always

Before you commit, search the file for <<<<<<<, ======= and >>>>>>>. If any is left, the file is not finished. Run git status: when no "Unmerged paths" remain, run git commit. Run your project or tests once before you move on.

When it goes wrong

related messages
error: Your local changes to the following files would be overwritten by mergeCommit or stash firstSave your work with a commit, or park it with git stash, then merge again.
fatal: not a git repository (or any of the parent directories): .gitYou are not inside a repositorySee the fix for this error.

Questions people ask

What do the <<<<<<<, ======= and >>>>>>> lines mean?

The top part, after <<<<<<< HEAD, is your current branch. The bottom part, before >>>>>>>, is the branch you are merging. ======= separates them. They are only markers, and you must delete them.

How do I cancel a merge conflict?

Run git merge --abort. It returns the repository to its state before the merge began.

How do I finish after fixing the file?

Run git add on each fixed file, then git commit. Git offers a ready-made merge message.

Will I lose my work in a conflict?

No. Both versions are in the file until you delete one. Your earlier commits stay safe on their branches.

Git, Visually · Parts 1 to 3 · English