Try it: open and merge a pull request

Reading · 15 min · Module 7, lesson 3 of 526 min left in this module

Module 7 · GitHubLesson 3 of 5

Goal: Complete a review cycle on GitHub, from a pull request with a conflict to a merge.

You need A free GitHub account, signed in, in your browser. Everything happens on github.com.

About the sample

learn-merge-conflict is the repository you used in lesson 2.5.4. Its main branch changed the greeting in greeting.js from "Hello, world" to "Good day, world". The friendly-greeting branch started before that and changed the same line to "Hey there, world!", so the two conflict.

  1. Fork the sample, with all its branches

    Open computesphere-samples/learn-merge-conflict and choose Fork. Leave Copy the main branch only unticked, so the fork gets friendly-greeting too, then choose Create fork.

    You should seeYour own learn-merge-conflict, with main and friendly-greeting in its branch list.

  2. Start a pull request inside your fork

    In your fork, open the Pull requests tab and choose New pull request. GitHub assumes you want to send changes back to the original, so it sets the base repository to computesphere-samples/learn-merge-conflict. Open that dropdown and choose your fork instead. Then set base to main and compare to friendly-greeting.

    GitHub warns that the branches can't be merged automatically. That's expected: you can still open the pull request.

    You should seebase repository: your-name/learn-merge-conflict, base: main, compare: friendly-greeting, and a diff of greeting.js.

  3. Describe it and create it

    Choose Create pull request. Title it "Use a friendlier greeting", and in the description say why and how you checked it, as in lesson 2.7.1. Choose Create pull request again.

    You should seeAn open pull request, with a warning that the branch has conflicts and a Resolve conflicts button.

  4. Resolve the conflict in GitHub's editor

    Choose Resolve conflicts. Between the markers you'll see both greetings. Keep the one you want (say, "Hey there, world!"), delete the other and all three marker lines, then choose Mark as resolved and Commit merge.

    GitHub's editor handles simple conflicts like this one, where two branches changed the same lines. Bigger ones need the command line, as in lesson 2.5.4.

    GitHub asks which branch to commit to

    Choose I understand, continue updating friendly-greeting. The merge commit goes on your branch, not on main.

    You should seegreeting.js with one greeting and no conflict markers left, then the pull request says it can be merged.

  5. Review your own change

    Open Files changed. Hover over the greeting line, choose the blue comment icon, and write a comment a reviewer might leave, for example "Should the greeting come from configuration?" Choose Start a review, then Review changes, Comment and Submit review.

    You can't approve your own pull request. On a team, someone else does that.

    You should seeYour comment on the greeting line, and Approve unavailable.

  6. Merge it

    Back on the Conversation tab, scroll to the bottom and choose Merge pull request, then Confirm merge. Delete branch tidies up friendly-greeting; its commits are safe in main now.

    You should seeThe pull request shows Merged, and main's greeting.js has the greeting you kept.

Check yourself

When you chose Commit merge in step 4, where did the merge commit go?
In step 2, what would have happened if you'd left the base repository as computesphere-samples/learn-merge-conflict?