Ffile2fix
Sign in Get started

Fix Git "Automatic merge failed; fix conflicts and then commit the result"

CONFLICT (content): Merge conflict in src/app.js
Automatic merge failed; fix conflicts and then commit the result.

Both branches changed the same lines (or one changed a file the other deleted), so Git cannot choose automatically and stops mid-merge. Edit each conflicted file to keep the right content, stage it with git add, and finish with git commit, or back out with git merge --abort.

Also appears as: error: Pulling is not possible because you have unmerged files. · error: you need to resolve your current index first · CONFLICT (modify/delete): config.php deleted in HEAD and modified in feature. Version feature of config.php left in tree. · error: could not apply 1a2b3c4... Update header hint: Resolve all conflicts manually, mark them as resolved with "git add/rm <conflicted_files>", then run "git rebase --continue".

Common causes

  • Two branches edited the same lines of a file
  • One branch deleted or renamed a file that the other modified
  • A long-lived feature branch drifted far from main
  • git pull merged remote commits into local changes to the same file
  • Generated files such as lock files or built assets were committed and changed on both sides
  • Different line endings or reformatting touched every line of a file

How to fix it

  1. List the conflicted files. Run git status. Files under 'Unmerged paths' marked 'both modified' or 'deleted by them' are the ones to fix.
  2. Edit the conflict markers. Open each file and find the <<<<<<<, ======= and >>>>>>> blocks. Keep the correct code, combine both sides if needed, and delete all three marker lines.
  3. Take one side for whole files. For a file where one version should win, run git checkout --ours path or git checkout --theirs path. During a rebase, ours and theirs are swapped: ours is the branch you are rebasing onto.
  4. Stage and finish. Run git add on each resolved file (or git rm for a deletion you accept), then git commit or git merge --continue. During a rebase use git rebase --continue.
  5. Abort if needed. git merge --abort (or git rebase --abort) returns the branch to its state before the merge. Use it when you want to start over or merge later.
  6. Regenerate lock files. For package-lock.json or composer.lock conflicts, take one side, then run npm install or composer update --lock to regenerate it, and commit the result.

Terminal

git status                       # see unmerged paths
# edit files, remove <<<<<<< ======= >>>>>>> markers
git add src/app.js
git commit                       # or: git merge --continue

# start over
git merge --abort

How to stop it happening again

  • Merge or rebase main into feature branches often so they stay close
  • Keep pull requests small and short-lived
  • Add a .gitattributes with consistent line endings and agree on a formatter
  • Do not commit generated or build files; regenerate them instead

Frequently asked questions

How do I know I removed every conflict marker?

Run git diff --check, which reports leftover conflict markers and whitespace errors, or search the project for <<<<<<<. Git will commit files that still contain markers, so checking yourself matters.

What is the difference between ours and theirs?

In a merge, ours is your current branch and theirs is the branch being merged in. In a rebase they are reversed, because Git replays your commits on top of the other branch.

Can Git remember how I resolved a conflict?

Yes. Enable git config --global rerere.enabled true and Git records resolutions and reapplies them when the same conflict appears again, which helps with repeated rebases.