Merge conflicts happen all the time, and knowing how to resolve them is one of the most important skills a software engineer should have.
In this scenario, Feature A has been approved and merged into the main branch. However, there is some code in Feature A that is incompatible with Feature B, which means that Feature B cannot be directly merged in. The developer who worked on Feature B will now have to account for those changes.
- Use
git branchto confirm that you are still on thefeature-Bbranch.
- Run
git fetch origin main:mainto update your local main branch with the changes on the remote main branch. - Run
git merge mainto merge in the changes from themainbranch into the current feature branch. You will run into a conflict! The error message will tell you which file needs to be fixed. In this example, you will need to fixREADME.md. - In
README.md, you will see merge conflict syntax. Read more this syntax in step 5 of GitHub's guide on merge conflicts.
- VS Code provides some helpful tooling to resolve merge conflicts. In this example, select Accept Both Changes, which will remove the merge conflict markers.

- Save your changes to
README.md. - In the terminal, run
git add README.mdandgit commitwithout a message. An editor will appear with a default merge message. You can simply close it. - Run
git pushto update the remote feature branch with your fixes.
Once Student B has pushed their changes, their pull request will be automatically updated on GitHub!
Student A should follow the steps in the previous section to approve and merge Student B's pull request. If there is a Student C, then Student C should do this instead.
Congrats! You've just resolved your first merge conflict!
If you are in a team of 3, then Student C should now repeat the steps that student B just did to resolve the merge conflict. Student A should review.
In summary:
- Student B reviews and merges Student A's PR.
- Student B fixes their own PR.
- Student C reviews and merges Student B's PR.
- Student C fixes their own PR.
- Student A reviews and merges Student C's PR.
→ Continue to Cleanup