/errors/git/merge-conflict-automatic-merge-failed
Git: CONFLICT (content): Automatic merge failed; fix conflicts and then commit the result.
- 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
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 --graphOutput
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
| Command | What it does |
|---|---|
| git status | Lists conflicted files under "Unmerged paths" |
| git diff | Shows the conflicts in all unresolved files |
| git checkout --ours FILE | Takes your branch version of the whole file |
| git checkout --theirs FILE | Takes the other branch version of the whole file |
| git add FILE | Marks FILE as resolved |
| git merge --continue | Same as git commit once every file is resolved |
| git merge --abort | Cancels the merge and restores the pre-merge state |
| git mergetool | Opens 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.