How to fix CONFLICT (content): Merge conflict in file.txt Automatic merge failed; fix conflicts and then commit the result in Git

GitBEGINNERMEDIUMUpdated Dec 6, 2025ยท 221 views

Git merge conflicts occur when competing changes are made to the same lines of a file across different branches. To resolve this, you must manually edit the conflicted files to choose the correct changes, then stage and commit the result.

Quick fix

Fixes CONFLICT (content): Merge conflict in file.txt Automatic merge failed; fix conflicts and then commit the result

# Show the current status with conflict information
git status

# You'll see output like:
# On branch main
# You have unmerged paths.
#   (fix conflicts and run "git commit")
#   (use "git merge --abort" to abort the merge)
#
# Unmerged paths:
#   both modified:   file.txt
#   both modified:   src/component.js
  1. Check which files have conflicts
  2. Open and understand the conflict markers
  3. Resolve the conflict by editing the file
  4. Mark the conflict as resolved and commit
git โ€” error
# Show the current status with conflict information
git status
# You'll see output like:
# On branch main
# You have unmerged paths.
# (fix conflicts and run "git commit")
# (use "git merge --abort" to abort the merge)
#
# Unmerged paths:
# both modified: file.txt
# both modified: src/component.js
CONFLICT (content): Merge conflict in file.txt Automatic merge failed; fix conflicts and then commit the result

What this error means

This error occurs when Git cannot automatically combine changes from two branches because both branches have modified the same lines in a file. Git is unable to determine which changes should take precedence, so it marks the file as conflicted and requires manual intervention. When you see "CONFLICT (content): Merge conflict in file.txt", Git has identified that the same section of code was changed in both the branch you're on and the branch you're trying to merge. The "Automatic merge failed" message confirms that Git couldn't resolve this on its own. Git uses a three-way merge algorithm that compares the two branch heads with their common ancestor. When changes on both sides affect the same lines, Git cannot determine the correct resolution and instead inserts conflict markers into the file, leaving the final decision to you.

Typical symptoms

  • Merge or pull operation stops with 'CONFLICT' messages
  • Files contain conflict markers (<<<<<<, =======, >>>>>>>)
  • 'git status' shows 'both modified' or 'Unmerged paths'
  • Unable to commit until conflicts are resolved
  • Merge is in progress but not complete
  • Error during 'git pull' from remote repository
  • Rebase operation stops and requires conflict resolution
  • Cherry-pick fails with merge conflict

Common causes

  1. Two branches modified the same lines of a file differently
  2. One branch deleted a file that another branch modified
  3. Parallel development on the same feature without regular syncing
  4. Rebasing a branch that has diverged significantly from the base
  5. Cherry-picking commits that conflict with existing changes
  6. Merging a long-lived feature branch with many accumulated changes
  7. Auto-formatting or line ending changes across the codebase
  8. Refactoring in one branch while another adds new code in the same area

How to fix "CONFLICT (content): Merge conflict in file.txt Automatic merge failed; fix conflicts and then commit the result"

1Check which files have conflicts

First, identify all files with merge conflicts:

bash
# Show the current status with conflict information
git status

# You'll see output like:
# On branch main
# You have unmerged paths.
#   (fix conflicts and run "git commit")
#   (use "git merge --abort" to abort the merge)
#
# Unmerged paths:
#   both modified:   file.txt
#   both modified:   src/component.js

You can also use:

bash
# List only conflicted files
git diff --name-only --diff-filter=U
2Open and understand the conflict markers

Open each conflicted file in your editor. Git inserts special markers to show the conflicting changes:

text
<<<<<<< HEAD
This is the content from your current branch (HEAD)
=======
This is the content from the branch being merged
>>>>>>> feature-branch

Understanding the markers:
- <<<<<<< HEAD: Start of your current branch's version
- =======: Separator between the two versions
- >>>>>>> feature-branch: End of the incoming branch's version

With diff3 style (recommended):

bash
git config merge.conflictstyle diff3

This shows three sections including the common ancestor:

text
<<<<<<< HEAD
Your changes
||||||| merged common ancestor
Original content before both changes
=======
Their changes
>>>>>>> feature-branch
3Resolve the conflict by editing the file

Edit the file to resolve the conflict. You have several options:

Option 1: Keep your version
Remove the markers and the other version:

text
This is the content from your current branch (HEAD)

Option 2: Keep their version
Remove the markers and your version:

text
This is the content from the branch being merged

Option 3: Combine both versions
Merge the changes manually:

text
Combined content from both branches

Important: Remove ALL conflict markers (<<<<<<<, =======, >>>>>>>). Any remaining markers will cause syntax errors in your code.

Verify the resolution:

bash
# Search for any remaining conflict markers
grep -rn "<<<<<<" .
grep -rn "=======" .
grep -rn ">>>>>>" .
4Mark the conflict as resolved and commit

After editing all conflicted files, stage them and complete the merge:

bash
# Stage the resolved files
git add file.txt
git add src/component.js

# Or stage all resolved files at once
git add .

# Verify the resolution
git status
# Should show: "All conflicts fixed but you are still merging"

# Complete the merge with a commit
git commit
# Git will open your editor with a default merge commit message
# You can modify it or save as-is

Alternatively, commit with a custom message:

bash
git commit -m "Merge feature-branch into main, resolved conflicts in file.txt"
5Use a merge tool for complex conflicts

For complex conflicts, use a visual merge tool:

bash
# Launch the configured merge tool
git mergetool

# Git will open each conflicted file in your merge tool
# Resolve conflicts visually, save, and close

Configure a merge tool:

bash
# Set your preferred merge tool
git config --global merge.tool vscode
git config --global mergetool.vscode.cmd 'code --wait $MERGED'

# Other popular options:
git config --global merge.tool meld
git config --global merge.tool kdiff3
git config --global merge.tool vimdiff

Available built-in tools:
- vimdiff, gvimdiff
- kdiff3
- meld
- tortoisemerge
- opendiff (macOS)
- emerge

Remove .orig backup files after merging:

bash
git config --global mergetool.keepBackup false

# Or delete manually
find . -name "*.orig" -delete
6Choose one side automatically (when appropriate)

If you know you want to keep all changes from one side, use strategy options:

During merge:

bash
# Accept all changes from the current branch (ours)
git merge -X ours feature-branch

# Accept all changes from the incoming branch (theirs)
git merge -X theirs feature-branch

For individual files during conflict resolution:

bash
# Keep the current branch's version of a file
git checkout --ours file.txt
git add file.txt

# Keep the incoming branch's version of a file
git checkout --theirs file.txt
git add file.txt

Warning: Be careful with these options. They discard changes from one side without review. Only use when you're certain which version is correct.

7Abort the merge if needed

If you want to cancel the merge and return to the state before the merge started:

bash
# Abort the merge and restore pre-merge state
git merge --abort

This is useful when:
- You started a merge by mistake
- The conflicts are too complex and you need to prepare first
- You want to try a different merge strategy

After aborting, you might want to:

bash
# Update your branch first, then try again
git pull origin main
git merge feature-branch

# Or rebase instead of merge
git rebase main

Note: git merge --abort only works if you haven't committed yet. If you've already committed the merge, use:

bash
# Undo the merge commit
git reset --hard HEAD~1

Advanced notes

### Understanding Git's Three-Way Merge

Git uses a three-way merge algorithm that compares:
1. Base (common ancestor): The commit where both branches diverged
2. Ours (HEAD): The current branch's version
3. Theirs: The incoming branch's version

Conflicts only occur when both sides change the same lines relative to the base. If only one side changed a section, Git automatically takes that change.

### Using diff3 Conflict Style

Enable diff3 to see the original (base) version in conflicts:

bash
git config --global merge.conflictstyle diff3

This helps understand what was changed on each side by showing the original content.

### Conflict Types

| Type | Message | Meaning |
|------|---------|---------|
| content | CONFLICT (content) | Same lines modified |
| add/add | CONFLICT (add/add) | Both sides added a file |
| modify/delete | CONFLICT (modify/delete) | One modified, one deleted |
| rename/rename | CONFLICT (rename/rename) | Both renamed differently |
| rename/delete | CONFLICT (rename/delete) | One renamed, one deleted |

### Rerere: Reuse Recorded Resolution

Git can remember how you resolved conflicts and apply the same resolution automatically:

bash
# Enable rerere globally
git config --global rerere.enabled true

# Git will now record conflict resolutions
# Future identical conflicts are resolved automatically

### Avoiding Merge Conflicts

Best practices:
- Pull/rebase frequently to stay in sync
- Keep feature branches short-lived
- Communicate with team about files being modified
- Use smaller, focused commits
- Consider using trunk-based development

### Resolving During Rebase

Rebase conflicts work similarly but need different commands:

bash
# After resolving conflicts during rebase
git add <resolved-files>
git rebase --continue

# Or abort the rebase
git rebase --abort

# Skip the current commit
git rebase --skip

### The ORT Merge Strategy

Git 2.33+ uses the "ORT" (Ostensibly Recursive's Twin) strategy by default, which is faster and handles some edge cases better than the older "recursive" strategy.

### Checking for Conflicts Before Merging

bash
# Do a dry-run merge to see if conflicts would occur
git merge --no-commit --no-ff feature-branch
git diff --cached
git merge --abort

### Common IDE Integration

Most IDEs have built-in merge conflict resolution:
- VS Code: Click on conflict markers for options
- IntelliJ/WebStorm: VCS > Git > Resolve Conflicts
- Sublime Merge: Visual conflict resolution
- GitKraken: Interactive conflict editor

Frequently asked questions

What does "CONFLICT (content): Merge conflict in file.txt Automatic merge failed;" mean?
This error occurs when Git cannot automatically combine changes from two branches because both branches have modified the same lines in a file. Git is unable to determine which changes should take precedence, so it marks the file as conflicted and requires manual intervention. txt", Git has identified that the same section of code was changed in both the branch you're on and the branch you're trying to merge.
How do I fix "CONFLICT (content): Merge conflict in file.txt Automatic merge failed;"?
Git merge conflicts occur when competing changes are made to the same lines of a file across different branches. To resolve this, you must manually edit the conflicted files to choose the correct changes, then stage and commit the result.
What causes "CONFLICT (content): Merge conflict in file.txt Automatic merge failed;"?
Two branches modified the same lines of a file differently One branch deleted a file that another branch modified Parallel development on the same feature without regular syncing
Is the "CONFLICT (content): Merge conflict in file.txt Automatic merge failed;" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading