Skip to content

Commit 743ea89

Browse files
authored
Merge pull request #230 from thomaskileyukaea/move-branch-protection-to-extras
Move branch protection to extras
2 parents a49a0c1 + e72a406 commit 743ea89

4 files changed

Lines changed: 71 additions & 23 deletions

File tree

_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ extras_order:
9393
- guide
9494
- common-issues
9595
- discuss
96+
- protect-main-branch
9697
- vscode
9798
- functional-programming
9899
- persistence

_episodes/41-code-review.md

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,35 @@ and improve our code by engaging in code review process with other team members.
3030
> the type of development model you use in your project.
3131
> Two commonly used models are:
3232
>
33-
> - **fork and pull model** -
34-
> where anyone can **fork** an existing repository
35-
> (to create their copy of the project linked to the source)
36-
> and push changes to their personal fork.
37-
> A contributor can work independently on their own fork as they do not need
38-
> permissions on the source repository to push modifications to a fork they own.
39-
> The changes from contributors can then be **pulled** into the source repository
40-
> by the project maintainer on request and after a code review process.
41-
> This model is popular with open source projects as it
42-
> reduces the start up costs for new contributors
43-
> and allows them to work independently without upfront coordination
44-
> with source project maintainers.
45-
> So, for example, you may use this model when you are an external collaborator on a project
46-
> rather than a core team member.
47-
> - **shared repository model** -
48-
> where collaborators are granted push access to a single shared code repository.
49-
> Even though collaborators have write access to the main development and production branches,
50-
> the best practice of creating feature branches for new developments
51-
> and when changes need to be made is still followed.
52-
> This is to enable easier testing of the new code
53-
> and initiate code review and general discussion about a set of changes
54-
> before they are merged into the development branch.
55-
> This model is more prevalent with teams and organisations collaborating on private projects.
33+
> * Fork and pull model
34+
> * Shared repository model
35+
>
36+
> **Fork and Pull Model**
37+
>
38+
> In this model, anyone can **fork** an existing repository
39+
> (to create their copy of the project linked to the source)
40+
> and push changes to their personal fork.
41+
> A contributor can work independently on their own fork as they do not need
42+
> permissions on the source repository to push modifications to a fork they own.
43+
> The changes from contributors can then be **pulled** into the source repository
44+
> by the project maintainer on request and after a code review process.
45+
> This model is popular with open source projects as it
46+
> reduces the start up costs for new contributors
47+
> and allows them to work independently without upfront coordination
48+
> with source project maintainers.
49+
> So, for example, you may use this model when you are an external collaborator on a project
50+
> rather than a core team member.
51+
>
52+
> **Shared Repository Model**
53+
>
54+
> In this model, collaborators are granted push access to a single shared code repository.
55+
> By default, collaborators have write access to the main branch.
56+
> However, it is best practice to create feature branches for new developments,
57+
> and protect the main branch. See the extra on [protecting the main branch](../protect-main-branch)
58+
> for how to do this.
59+
> While it requires more upfront coordination, it is easier to share each others
60+
> work, so it works well for more stable teams.
61+
> This model is more prevalent with teams and organizations collaborating on private projects.
5662
{: .callout}
5763

5864
Regardless of the collaborative code development model you and your collaborators use -

_extras/protect-main-branch.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
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+
![GitHub add a branch protection rule settings screen with recommended settings enabled for a branch called main](../fig/github-branch-protection-settings.png)
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).
65.8 KB
Loading

0 commit comments

Comments
 (0)