13  Main branch protection

Learning Objectives

  1. Set-up main branch protection on a GitHub repository
  2. Review and merge a pull request with main branch protection

Once we have developed the first working version of our software (that will be the end of week 2 for us in this course), we want to consider our main branch as the deployment branch.

What do we mean by deployment branch? Here we mean that other people may be using and depending on it, and thus, if we push changes to main they must not break things!

How do I make sure changes won’t break things?

There are varying levels of checks and balances that can be put in place to do this. One fundamental practice is main branch protection. Here we essentially put a rule in place that no one can push directly to main, all changes to main must be sent via a pull request so that at least one entity (e.g., human) can check things over before the change gets applied to the main (i.e., deployment) branch.

Readings: - About protected branches.

13.1 How to accept a pull request on a GitHub repository that has main branch protection

(note: at the time of video making, the default branch on GitHub as still called the master branch)

ExerciseExercise

Setting up main branch protection

We are going to practice setting up main branch protection. Once we set this up on our play repository linked to below, we will practice branching and pull requests to send changes to the main branch in a later exercise.

13.1.1 Steps:

  1. Import a copy of this GitHub repository (need help? see: How to import a GitHub repository)

  2. Add main branch protection to your copy of this repository by going to Setting > Branches > Branch protection rules and selecting “Add branch protection rule”. Add “main” as the Branch pattern name and tick the box “Require a pull request before merging”. Keep “Require approvals” selected as well.

  3. Try to make a change by pushing directly to the main branch

Relevance-projectRelevance to course project

You are not required to use this for the project, but it can be useful on the job. Especially when you add new developers or maintainers to your GitHub repos.