How to Resolve Conflicts in GitHub Step by Step
Conflicts in GitHub happen when multiple changes affect the same code. If not fixed, you cannot merge branches. This guide explains how to resolve conflicts in GitHub quickly and safely.
Table of contents
How to Resolve Conflicts in GitHub
1. Use the Terminal
Follow these steps in your terminal:
- Run the following to update your local repository:
git fetch origin - Switch to your working branch with
git checkout branch-name - Merge the target branch using
git merge target-branch - Git will flag conflicts if they exist.
- Open the conflicted files and look for <<<<<<<, =======, and >>>>>>> markers.
- Manually edit the sections to keep the correct changes and remove conflict markers.
- Save the file, then stage it with
git add filename - Commit the fix using
git commit - Push your updated branch to GitHub with
git push origin branch-name
This method gives you the most control over the final result. If you want more guidance on working with branches, see this guide on how to merge branches in GitHub.
2. Resolve Conflicts in GitHub Web or IDE
You can also fix conflicts without Git commands:
- Open your pull request on GitHub.
- Click Resolve conflicts.
- Use the built-in editor to fix issues, then save and commit.
- In Visual Studio Code, open the conflicted file.
- Choose whether to accept current changes, incoming changes, or both.
- Save and commit directly in your IDE.
These approaches are easier for quick edits or smaller projects. For related tasks, you may find it useful to check this guide on how to download a GitHub folder.
Once you have resolved conflicts in a pull request, the next step is learning how to approve a pull request on GitHub so the changes can be merged successfully.
Best Practices to Avoid Conflicts
- Pull from the main branch often to reduce drift.
- Communicate with teammates before making large edits.
- Keep feature branches short-lived.
- Use pull requests and code reviews to detect overlaps early.
Why GitHub Conflicts Occur
- Two branches change the same line of code.
- A file is deleted in one branch but edited in another.
- Branches drift apart and overlap with different edits.
You must manually review and fix them before merging.
FAQs
You will see a merge conflict error in your terminal or pull request.
Yes. VS Code highlights conflicts and provides buttons to accept current, incoming, or both changes.
The conflict remains in the active branch until resolved. Always fix before deleting.
Git can handle simple merges automatically, but when changes overlap, you must manually decide which code to keep.
Conclusion
Resolving conflicts in GitHub may feel challenging at first, but the process is straightforward once you know the steps. Use Git commands for full control, or the web and IDE editors for quick fixes. By practicing good branch management and communication, you can minimize conflicts and keep your projects running smoothly.
If you want to improve repository organization, it also helps to learn how to create a folder in GitHub. To keep your workflow consistent after resolving conflicts, you may also want to learn how to change the default branch in GitHub so your team always works on the right branch.
Read our disclosure page to find out how can you help Windows Report sustain the editorial team. Read more



User forum
0 messages