How to resolve a Git merge conflict without panicking
A merge conflict happens when you changed the same part of the same file differently in two branches and then merge them. Git has not failed here; it has paused and is waiting for you to decide. Here is how to read the situation and resolve it, per the official Pro Git book.
What a conflict looks like
$ git merge iss53 Auto-merging index.html CONFLICT (content): Merge conflict in index.html Automatic merge failed; fix conflicts and then commit the result.
Git did not create a merge commit; it stopped the process until you resolve the conflict yourself.
See which files conflict
Run git status any time after a conflict. Conflicted files appear under Unmerged paths marked both modified.
Open the file and read the markers
Git adds standard conflict markers inside the file:
<<<<<<< HEAD:index.html <div id="footer">contact : email.support@github.com</div> ======= <div id="footer"> please contact us at support@github.com </div> >>>>>>>> iss53:index.html
The top part (above =======) is your current branch's version (HEAD), the bottom is the branch you are merging in. Your job: pick one side or merge both into new text, then delete all three marker lines.
Mark it resolved
- Edit the file until only the correct content remains, with no
<<<<<<<,=======or>>>>>>>markers left. - Run
git addon the file to tell Git the conflict is resolved. - Finish the merge with
git commit.
You can also run git mergetool to open a graphical merge tool that helps you choose between versions; the book lists opendiff, kdiff3, meld, vimdiff and others.
Verify, then commit
After resolving and staging every file with git add, run git status one last time. The line you are waiting for:
All conflicts fixed but you are still merging. (use "git commit" to conclude merge)
Then run git commit to finalize the merge; the default commit message includes the list of conflicted files under a Conflicts line.
Common mistakes
- Committing the file with conflict markers still inside, breaking the build or the page.
- Always picking one side without reading the other, silently dropping a teammate's work.
- Panicking and deleting the repository; a conflict is a normal state, not a failure.
For more Git reads see our .gitignore guide. And if your team needs help setting up development and deployment workflows, see our systems engineering service.
