How to resolve Git merge conflicts
· Category: Git
Short answer
When Git cannot automatically merge changes, it marks conflicts in the files. Edit the files to resolve them, then stage and commit.
Steps
- Identify conflicted files:
git status
- Open the file and look for conflict markers:
<<<<<<< HEAD
your changes
=======
their changes
>>>>>>> branch-name
- Edit to keep the desired code, removing markers.
- Stage and complete the merge:
git add .
git commit
Tips
- Use a merge tool like
git mergetoolor VS Code's built-in resolver. - Communicate with teammates when resolving complex conflicts.
git diffduring a merge shows only conflicted regions.
Common issues
- Accidentally committing conflict markers will break your code.
- Binary file conflicts require choosing one version manually.