Skip to content

/errors/git/merge-conflict-automatic-merge-failed

Git: CONFLICT (content): Automatic merge failed; fix conflicts and then commit the result.

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · git version 2.55.0.windows.5updated
tool
Git
exit code
1
versions
Git 2.x
os
any

CONFLICT (content): Merge conflict in app.conf followed by Automatic merge failed; fix conflicts and then commit the result. means both branches changed the same part of app.conf, and Git cannot decide which version to keep. The merge is paused, not lost: edit the file to the content you want, remove the conflict markers, git add the file and git commit. To cancel instead, run git merge --abort.

Reproduce and resolve it

bash
git init -q -b main repo && cd repo
printf 'port=8080\nhost=localhost\n' > app.conf
git add app.conf && git commit -q -m "base config"
git switch -q -c feature
sed -i 's/port=8080/port=9090/' app.conf && git commit -q -am "feature: use port 9090"
git switch -q main
sed -i 's/port=8080/port=3000/' app.conf && git commit -q -am "main: use port 3000"
git merge feature
echo "--- git status --short"
git status --short
echo "--- app.conf"
cat app.conf
echo "--- resolve: keep 9090, then add and commit"
printf 'port=9090\nhost=localhost\n' > app.conf
git add app.conf
git commit -q --no-edit
git log --oneline --graph

Output

Auto-merging app.conf
CONFLICT (content): Merge conflict in app.conf
Automatic merge failed; fix conflicts and then commit the result.
--- git status --short
UU app.conf
--- app.conf
<<<<<<< HEAD
port=3000
=======
port=9090
>>>>>>> feature
host=localhost
--- resolve: keep 9090, then add and commit
*   1928e2f Merge branch 'feature'
|\
| * 69c0a15 feature: use port 9090
* | c28bc46 main: use port 3000
|/
* c9910ee base config

UU in git status --short means "unmerged, both modified". The block between <<<<<<< HEAD and ======= is your current branch (main); the block between ======= and >>>>>>> feature is the branch being merged. Lines outside the markers (host=localhost) merged cleanly.

Useful commands during a conflict

CommandWhat it does
git statusLists conflicted files under "Unmerged paths"
git diffShows the conflicts in all unresolved files
git checkout --ours FILETakes your branch version of the whole file
git checkout --theirs FILETakes the other branch version of the whole file
git add FILEMarks FILE as resolved
git merge --continueSame as git commit once every file is resolved
git merge --abortCancels the merge and restores the pre-merge state
git mergetoolOpens the configured visual merge tool for each file

During a rebase the same markers appear, but --ours is the branch you are rebasing onto and --theirs is your commit being replayed; finish with git rebase --continue or cancel with git rebase --abort.

Sources