Resolving merge conflicts on the ClassicPress GitHub

What to do when two pull requests change the same part of a file

There has been some interest / questions about resolving merge conflicts on GitHub. This happens when two pull requests (PR) change the same part of a file in different ways. We have an example of such a PR here, so I’ll walk through the steps I’m taking to resolve the conflict.

Resolving Merge Conflicts

Conflicting Code

There are GUI tools that make this easier to understand, but basically: there are two different versions of this file, and this interface is asking me which one is correct.

In between the <<<<<<< and ======= markers, there is this line:
/tests/phpunit/data/plugins/wordpress-importer

This corresponds to my PR: “This line was left in your PR”.

But, in between ======= and >>>>>>>, there is nothing: “This line was deleted in the `master` branch”.

This is because I deleted the line *below* that one in my PR, and in another PR the line that has the conflict was also deleted. So, in this case, the way to resolve the conflict is to delete that entire section

Deleting Section Of Code

The next conflict is similar: I removed this whole section in this PR, but it was modified elsewhere. Since I still want to remove it, I’ll resolve the conflict by just removing that whole section.

Merge Conflicts

Last one! In this case, this section was _modified_ in two different PRs, and I need to decide what the final version should be after all these changes.

Remove Conflicts

Mark As Resolved

After resolving all conflicts, you get a “Commit merge” button, which adds a new commit to the PR:

Commit Merge

All done, now just waiting for the automated tests to make sure I didn’t break anything 😉

Has this whet your appetite for knowledge of GitHub? You’re in luck. We’ve got a load more GitHub tutorials for you to read.

Notable Replies

  1. Avatar for klein klein says:

    Hello, some context for the sudden appearance of this thread. This was an old tutorial written by @scott on Classicpress.net that didn’t have a thread linked to it. Since we are now making more tutorials and have a place to collect them, I decided to add this tutorial to our growing category here on the forum. Hope it is useful.

Continue the discussion at forums.classicpress.net

Participants

Avatar for klein Avatar for system