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
- Run the command
git statusto identify the conflicting files. - Open the conflicting files and look for the conflict markers (
<<<<<<<,=======, and>>>>>>>). - Manually resolve the conflicts by editing the files and removing the conflict markers.
- Run the command
git addto stage the resolved files. - Run the command
git merge --continueto 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:
| |
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 --rebaseinstead ofgit pullto rebase your local changes on top of the updated remote branch. - Use
git merge --no-ffto 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.