Exercise - Add a rule to require a review


In this unit, you set up a rule on GitHub that requires a reviewer to approve changes before they can be merged into the main branch. As a bonus, you'll also fix the typing error on the Space Game website's home page.

Currently, the team allows anyone who makes a pull request to merge the code into the main branch. Because no review is required, it's possible for incorrect or unstable code to creep in.

Andy decides that he wants to add a check to the pull request in the form of another pair of eyes. He wants to set up GitHub to require someone other than the pull request author to review the code before it's merged. Let's see how to do this.

Andy heads off to find Mara and spots her at her desk working away, her head bobbing to the music in her earbuds.

Andy: Mara, I've been meaning to talk to you about something.

Mara looks up.

Mara: What can I help you with?

Andy: Several small mistakes are making it through the build. Just today, a typing error showed up on the home page. Amita is spending too much time on these things. We need to stop them before they make it to the main branch. We need another pair of eyes on the code before the pull request is approved.

Mara: I can set that up. In GitHub, there's a way to make sure that no pull request is merged before someone else reviews and approves it.

Set up approvals

In this section, you set up a rule on GitHub that requires at least one reviewer to approve a pull request before it can be merged into the main branch. You set up the rule and then verify that it works by pushing up a fix to the typing error that Mara made earlier.

Add the rule

  1. In GitHub, go to your Space Game project repository.
  2. Select the Settings tab near the top of the page.
  3. On the menu, select Branches.
  4. Make sure that main is selected as your default branch.
  5. Select Add rule.
  6. Under Branch name pattern, enter main.
  7. Select the Require pull request reviews before merging check box.
  8. Keep the Required approving reviews value at 1.
  9. Select Create.
  10. Select Save changes.


At the bottom of the list of choices is an option named Include Administrators. This option requires repository administrators to follow the rule. You don't set that, because you're an administrator of your repository and there isn't another reviewer. In this unit, for learning purposes, you review and approve your own pull requests.

Submit the fix

In this section, you submit a fix to the typing error on the home page. Recall that the word "official" is mistyped as "oficial".

A screenshot of the Space Game website showing a typing error.

  1. In Visual Studio Code, go to the terminal.

  2. To check out the main branch, run git checkout:

    git checkout main
  3. To pull down the latest changes to the main branch from GitHub, run git pull:

    git pull origin main

    You can see that two files are updated:

    • README.md: Contains the Markdown code for displaying the build badge.
    • Index.cshtml: Contains the updated home page text, which includes the typing error.
  4. To fix the error, create and check out a branch:

    git checkout -B bugfix/home-page-typo
  5. In File Explorer, open Index.cshtml.

  6. Locate the error.

    <p>Welcome to the oficial Space Game site!</p>
  7. Change the line to correct the error.

    <p>Welcome to the official Space Game site!</p>
  8. Save the file.

  9. In the terminal, stage and commit the change.

    git status
    git add Tailspin.SpaceGame.Web/Views/Home/Index.cshtml
    git commit -m "Fix typing error on the home page"

    In practice, you would ordinarily build and run the site locally to verify the change. In this unit, for the sake of brevity, let's skip that step.

  10. Push the branch to GitHub.

    git push origin bugfix/home-page-typo

Test the rule

  1. In GitHub, locate and select the bugfix/home-page-typo branch.

    A screenshot of GitHub showing the recently pushed branch.

  2. To start your pull request, select Contribute and then Open pull request.

  3. Set your forked repository as the base repository.

    A screenshot of GitHub confirming that the branch can be merged.

  4. Select Create pull request.

    You can see that a human review is required before you can merge the change.

    A screenshot of a pull request on GitHub showing that a review is required in order to merge.

    In practice, you would assign a team member to review your change. In this unit, for learning purposes, you merge your own pull request.

  5. To merge the pull request, select Merge pull request.

  6. Select the Use your Administrator privileges to merge this pull request check box, and then select Confirm merge.

    Your change is merged.

  7. To delete the bugfix/home-page-typo branch, select Delete branch.