5 Merge conflicts
Learning Objectives
- Explain why merge conflicts happen and identify Git’s merge conflict markers
- Resolve merge conflicts in a plain text file and in a Jupyter notebook
One of the major blockers getting used to using version control is dealing with merge conflicts! 😱
Git can automatically handle merging two versions of a file if each collaborator changes different lines, however when two collaborators change the same line, Git throws up its hands and says, I cannot handle this responsibility, I need help from a human!

When this happens, your human task is to find the merge conflict markers, remove them, and settle on which version of the line(s) where the conflict occurred should remain. Merge conflict markers include:
<<<<<<< HEADto indicate the beginning of the merge conflict>>>>>>>to indicate the end of the merge conflict=======between the markings mentioned above to indicate the boundary between the two proposed changes. The version of the change before the separator is your > change, and the version that follows the separator was the change that existed on GitHub.
We are going to now generate and resolve merge conflicts.I have set-up a template GitHub repository for you so that you can easily generate a merge conflict to resolve. We will do this twice, once with a simple plain text file (e.g., an R script) and once with a more complex text file (e.g., a Jupyter notebook).
Resolving merge conflicts in a simple text file:
Click the green “Use this template” button from this GitHub repository to obtain a copy of it for yourself (do not fork it).
Clone this repository to your computer.
Click on the Actions tab, and then click on the workflow .github/workflows/main.yml. You then should see a “Run workflow” button with a drop down menu, from that menu select “Run workflow” (this will trigger GitHub Actions to create a commit in your remote repository).
Locally on your computer, fix the second line in
cube.rso that it calculates the cube, not the square (e.g., changex^2tox^3). Commit your changes to version control via Git and push your changes to GitHub.Resolve the merge conflict them so that you can see your changes on GitHub.
Resolving merge conflicts in a more complex text file:
Click the green “Use this template” button from this GitHub repository to obtain a copy of it for yourself (do not fork it).
Clone this repository to your computer.
Click on the Actions tab, and then click on the workflow .github/workflows/main.yml. You then should see a “Run workflow” button with a drop down menu, from that menu select “Run workflow” (this will trigger GitHub Actions to create a commit in your remote repository).
Fix the second line in the code cell in
cube.ipynbso that it calculates the cube, not the square (e.g., changex^2tox^3). Commit your changes to version control via Git and push your changes to GitHub.Resolve the merge conflict them so that you can see your changes on GitHub.