Working together on GitHub · lesson 4 of 7
Commands and ideas in this lesson
AMerge boxreviews, checks, conflicts, the merge button
BResolve conflictsGitHub's conflict editor
CReverta new pull request that undoes a merged one
DConflict markersfrom lesson 3.4

Merging on GitHub

Last updated

A pull request has been reviewed and approved. Now someone presses Merge, and sometimes GitHub says it can't. In this lesson you'll read GitHub's merge box, settle a simple conflict in GitHub's own editor, tidy up the branch afterwards, and undo a merged pull request with Revert.

By the end of this lesson you can

  • Read the merge box: reviews, checks, and whether the branch has conflicts
  • Settle a simple conflict in GitHub's conflict editor, and know when to do it on your computer instead
  • Delete a merged branch, and undo a merged pull request with Revert

The merge box

At the bottom of a pull request's Conversation tab is the merge box. It says what's standing between the pull request and main:

  1. Reviews. Who approved or asked for changes (lesson 5.3). A branch rule can require approvals before merging.
  2. Checks. Automated checks, such as tests, that ran on the branch. Simple Software Development covers setting them up.
  3. Conflicts. Whether the branch can be merged into main without a clash. Step 2 is what to do when it can’t.
  4. Merge button. The arrow picks one of the three ways to merge from lesson 5.2: a merge commit, squash, or rebase.
The merge box at the bottom of a pull request. The course’s own drawing of this GitHub screen, with GitHub’s names for each part. A screenshot from the course’s demo account will replace it.

Merging happens on GitHub. Your computer's main doesn't have the merge until you git switch main and git pull.

This branch has conflicts

If main changed the same lines as the pull request since the branch started, the merge box says This branch has conflicts that must be resolved. For simple conflicts in text files, the Resolve conflicts button opens GitHub's editor, showing the same markers as lesson 3.4:

  1. File and count. Each file with conflicts, and how many.
  2. Markers. The pull request’s version above =======, main’s below. Edit the text to what it should be, and delete all three marker lines.
  3. Mark as resolved, then Commit merge. GitHub makes a merge commit on the pull request’s branch, merging main into it. The pull request can then be merged.
GitHub’s conflict editor. The course’s own drawing of this GitHub screen, with GitHub’s names for each part. A screenshot from the course’s demo account will replace it.

The editor only handles simple cases. Settle the conflict on your computer instead (fetch, switch to the branch, merge main, settle, commit, push, as in lesson 5.P) when:

  • the conflict is big, or in many files;
  • a file was deleted on one side, or renamed;
  • you need to test the result before it goes in, such as running a script.

If you can't push to the branch, as with someone else's fork, ask its author to settle it.

After merging

Once a pull request is merged, its branch has done its job. GitHub shows a Delete branch button: press it. If you need it back, Restore branch appears in the same place.

On your computer:

git switch main
git pull
git branch -d adobo-salt
git fetch --prune

git branch -d deletes your local copy of the branch (it refuses if the work isn't merged); --prune removes origin/adobo-salt, which no longer exists on GitHub. Start the next piece of work on a new branch from the updated main, as lesson 5.2's trap explained.

Undoing a merge

A merged pull request turns out to be wrong: Carla's kare-kare used the wrong oxtail weight, and the family cooked it. A merged pull request has a Revert button. It doesn't erase anything. It makes a new branch and a new pull request containing a commit that undoes the merge's changes, the same as git revert (lesson 2.5), and you review and merge that like any other.

History keeps both: the original merge and its revert. That's what you want on a shared branch, because others have already pulled the merge. Rewriting main to pretend it never happened would break their copies (lesson 6.3).

To fix the recipe properly, open a new pull request with the right amount. Reverting the revert is possible, but confusing to read later.

Spot the trap: merging your own

Spot the trapJoaquin

Joaquin has write access to the family’s Kusina. He opens a pull request changing the lumpia, and, since nobody has replied after ten minutes, merges it himself.

What happens if…

Check what you learned

You settle a conflict with GitHub’s Resolve conflicts editor. Where does the merge commit go?
What does GitHub’s Revert button on a merged pull request do?
A pull request has conflicts in six files, one of them renamed. Where should they be settled?

Sources

Every command on this page behaves as these pages describe, and the sandbox prints what Git 2.55 prints. Hosting features (pull requests, protected branches) come from the host’s own documentation.

All sources for Simple Git