Skip to content

Create Branch Protections

Tiffany Forkner edited this page Apr 2, 2025 · 6 revisions

Create a GitHub App

Follow the GitHub instructions for creating an app.

It should have at least the following permissions:

  • Actions Access: Read-only

Select read-only for Actions access

  • Contents Access: Read and write

Click read and write for Contents access

  • Metadata Access: Read-only (selected by default)

Leave read-only for Metadata access

Generate Private Key for GitHub App

Open your new GitHub App.

Open your new GitHub App

Scroll down to the Private keys section and click the “Generate a private key” button

Scroll down to the Private keys section and click the "Generate a private key button

This will automatically download a .pem file with your new private key to your computer.

Scroll back up and click on Install App and install your GitHub App in your repository.

Scroll to top and click on the Install App link in the left sidebar

Add Repository Keys

Open your new GitHub App and copy your “App ID” from your GitHub App

Open your new GitHub App and copy the App ID

Open your GitHub repository and click Settings > Secrets and variables > Actions

Open your GitHub repository and click the Settings tab and click Secrets and variables in the left sidebar and then click Action in the sub-menu

Click the “Variables” tab and click the “New repository variable” button

Click the Variables tab and click the New repository variable button

Enter “APP_ID” in the Name field and paste your App Id from above into the Value field. Click the “Add variable” button to save the variable.

Enter APP_ID in the Name field and past your app id from the GitHub app into the Value field

Click the Secrets tab and click the New repository secret button.

Click the Secrets tab and click the New repository secret button

Enter “PRIVATE_KEY” in the Name field. Copy the contents from the .pem file that was downloaded to your computer and paste it in the Secret field. Click the “Add secret” button.

Enter PRIVATE_KEY in the Name field and copy the contents from the .pem file that was downloaded to your computer and paste it in the Secret field

Create the Branch Protection Ruleset

Open GitHub and click on Settings > Branches

Open GitHub and click on the Settings tab and then Branches in the left sidebar

Click the “Add branch ruleset” button

Click the Add branch ruleset button

Name the rule and click the “Disabled” button and then click “Active”

Name the rule and click the Disabled button and click Active in the dropdown

Add your new GitHub Action as a bypass for the rule

Add your new GitHub Action as a bypass for the rule

Leave the bypass as “Always allow”

Leave the bypass as Always allow

Click the “Add target” button and then click “include by pattern”

Click the Add target button and then click include by pattern in the dropdown

Enter “gh-pages” into the Branch naming pattern field and click the “Add Inclusion pattern” button

Enter gh-pages into the Branch naming pattern field and click the Add Inclusion pattern button

Leave the default Branch rules selected and click Require a pull request before merging

Leave the default Branch rules select and click Require a pull request before merging

Set the options that you would like for pull request requirement

Set the options that you would like for pull request requirements

Click the “Create” button to save the ruleset


Clone this wiki locally