How to make protected branches on GitHub?

Tyree Harper
Strategio
Published in
2 min readApr 22, 2022

What Is GitHub?

GitHub is a code hosting platform owned by Microsoft for version control and collaboration. It lets you and others work together on projects from anywhere.

Why do you want to protect your branches?

After achieving a working build and getting hosted using the main branch, you or one of the collaborators accidentally pushed a test build onto the main branch, breaking the whole project. This causes significant delays, pointing of fingers, and downtime. What can an admin do to prevent project-breaking pushes from reaching the main?

Prerequisites

For you to proceed through this tutorial, ensure the following are completed:

  • GitHub account
  • A GitHub Repository
  • Mindfulness!

Tasks

Below is what'll be accomplished by the end of this tutorial:

  • Find project settings
  • Find branch setting
  • Add rules to branches
  • Add and remove collaborators
  1. select or make a GitHub repository that you are the owner of. I will be using an existing one that I own. We will set up protections on our main branch before adding others to the project.

2. Find the Repository settings on the main page of the repository

3. Under the "Code and automation" section of the sidebar, click Branches.

4. Next to "Branch protection rules" click Add Rule.

5. Type in the name of the branch you want to protect in the "Branch name pattern" box. It's common to protect the "main" branch.

6 Under "Protect matching branches" click on the "Require a pull request before merging" and it pulls down additional settings. You can make pull requests that need more than one approval before merging. The end result should look like this.

7. Click the green Create button at the bottom.

Congrats!

This branch is protected! No more accidental pushes reaching your main branch without anyone noticing!

--

--