You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: "Additional Material: Protecting the Main Branch on a Shared GitHub Repository"
3
+
---
4
+
5
+
## Introduction
6
+
7
+
By default, any collaborator can push to any branch on a shared repository.
8
+
It is possible to prevent this by "protecting" the main branch.
9
+
10
+
This has a number of advantages:
11
+
12
+
* Avoids someone accidentally pushing work-in-progress changes to the branch
13
+
that everyone else downloads.
14
+
* Ensures everyone follows a code review process.
15
+
* Ensures all changes are checked by continuous integration.
16
+
17
+
## How to protect the main branch
18
+
19
+
To protect the main branch in GitHub, go to the repository settings, select `Branches`.
20
+
Click `Add Rule`. Type in the name of your main branch (e.g. `main` and/or `develop`).
21
+
Tick the check box saying require pull requests. This will ensure all changes to the
22
+
branch are done via a pull request.
23
+
24
+

25
+
26
+
It is recommended to also tick `Require approvals`.
27
+
28
+
This means someone besides the person who raised the pull request will need to approve the change.
29
+
30
+
It is also recommended to tick `Require status checks before merging`.
31
+
32
+
This ensures that CI has run successfully before allowing the changes to be made.
33
+
34
+
Finally, it is recommended to tick `Do not allow bypassing the above settings`.
35
+
36
+
This means that administrators of the repository will have to follow the same process to.
37
+
If there becomes a need to push to the main branch, these settings can be changed
38
+
by administrators to allow this, setting this means that administrators cannot push by mistake
39
+
during the normal course of their work.
40
+
41
+
See [GitHubs documentation for more information about protecting branches](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/managing-a-branch-protection-rule).
0 commit comments