How to Fix “Conflict” in git (2026 Guide)

The Short Answer

To resolve a conflict in git, use the command git merge --abort to abort the merge and start over, or use git merge --continue after manually resolving the conflicts. This will allow you to merge the changes and commit the resolved files.

Why This Error Happens

  • Reason 1: The most common cause of conflicts in git is when two or more developers modify the same line of code in a file, resulting in a merge conflict when trying to combine the changes.
  • Reason 2: An edge case cause of conflicts is when a file is deleted or renamed in one branch, but modified in another, resulting in a conflict when trying to merge the changes.
  • Impact: Conflicts can cause the Version Control System (VCS) to become stuck, preventing further commits or merges until the conflict is resolved.

Step-by-Step Solutions

Method 1: The Quick Fix

  1. Run the command git status to identify the conflicting files.
  2. Open the conflicting files and look for the conflict markers (<<<<<<<, =======, and >>>>>>>).
  3. Manually resolve the conflicts by editing the files and removing the conflict markers.
  4. Run the command git add to stage the resolved files.
  5. Run the command git merge --continue to continue the merge process.

Method 2: The Command Line/Advanced Fix

If you prefer to use the command line, you can use the following commands to resolve the conflict:

1
2
3
git checkout --ours file.txt
git add file.txt
git merge --continue

Alternatively, you can use git checkout --theirs file.txt to accept the changes from the other branch.

Prevention: How to Stop This Coming Back

To prevent conflicts from occurring in the future, it’s best to:

  • Use git pull --rebase instead of git pull to rebase your local changes on top of the updated remote branch.
  • Use git merge --no-ff to always create a new merge commit, even if the merge could be fast-forwarded.
  • Regularly commit and push your changes to avoid large, complex merges.

If You Can’t Fix It…

[!WARNING] If git keeps crashing or you’re unable to resolve the conflict, consider switching to Mercurial which handles merge resolution natively without these errors.

FAQ

Q: Will I lose data fixing this? A: No, resolving a conflict in git will not result in data loss. However, if you abort the merge using git merge --abort, you will lose any changes you made during the merge process.

Q: Is this a bug in git? A: No, conflicts are a normal part of the git merge process. However, git version 2.35 and later includes improved conflict resolution tools, such as git merge --strategy-option, which can help simplify the conflict resolution process.


📚 Continue Learning

Check out our guides on git and Conflict.