Branch Protections

Overview

As you become increasingly familiar with Git workflows, utilizing branches for seamless collaboration will become commonplace. Branches allow each developer on your team to have a copy of the source code to work with.

Each developer can merge their code back into the main branch after completing their work. When all of the developers on a team have access to merge pull requests into the main branch it can cause security and quality issues. This is where a formalized code review process with branch protections comes into play.

Branch protection includes rules and configurations an Owner or Administrator of a repository can set to control who can edit the specific branch. Copia's branch protection features include the ability to:

  • Enable or disable pushing

  • Create whitelists of users or teams

  • Require approvals

  • Block merges automatically if certain criteria are met

  • Protect file patterns

Enabling branch protection and utilizing the features listed above can help to avoid unnecessary code commits, enforce code review workflows, and maintain the integrity of source code.

Setting Branch Protections

Navigate to the repository for which you want to enable Branch Protections.

Click on the Settings tab and select the Branches category.

On this screen, you can enable a variety of branch-related settings based on the needs of your Organization.

Choosing a Default Branch

If you choose one branch as the default branch, then all pull requests and code commits in the selected repository will point towards that branch.

To choose a default branch, find the Default Branch settings, click the branch dropdown, and make a selection. Click on the Update Settings button to save your default branch.

Enabling Branch Protection

If you enable branch protection, you can ensure that nothing is deleted and prevent pushing and merging to the branch.

Find the Branch Protection settings and click the branch dropdown. Choose the branch you want to protect.

Check the Enable Branch Protection option.

Once enabled, you can manage several granular settings related to Branch Protection.

  • Disable push - Prevents all users from being able to push to the branch.

  • Enable Push - Allows any user with a write seat to push an update to the selected branch.

  • Whitelist Restricted Push - Enables whitelisted users or Teams to push to the branch while blocking any other users from pushing. If you choose this setting, be sure to list user names and team names in the fields below the option.

Remember to click the Update Settings button to save your selections.

Both whitelisting options described above can be helpful tools when putting in place a code review workflow between end users and those tasked with code review or approval.

Aside from push disabling, enabling, and whitelisting, you can set a myriad of other granular settings related to Branch Protections.

Enable Merge Whitelist

This setting allows whitelisted users or teams to merge pull requests that have already been pushed to this branch. For this option, make sure to list user names and team names in the below fields.

Required Approvals

This feature allows you to set the minimum number of approvals required for a pull request to be merged. This can be useful in cases where multiple team members are tasked with reviewing new edits to code. By enabling this feature, a pull request will only be merged if the minimum number of positive reviews is received.

Restrict Approvals to Whitelisted Users or Teams

This option ties in with the previous feature, requiring a minimum number of approvals for whitelisted users. After setting your minimum required approvals you'll want to list the names of any users or teams who have authority to grant the positive reviews and allow the merge to occur.

Block Merge on Rejected Reviews

If one of your whitelisted reviewers determines edits or corrections need to be made, the reviewer can leave a comment and request a change to be made. By selecting this feature, that change request will block the merge from happening even if it technically met the minimum threshold for positive reviews.

The merge will only be blocked if the change request is made by a whitelisted reviewer.

Block Merge on Official Review Requests

If one of your whitelisted reviewers determines that edits or corrections need to be made, the reviewer can make an official review request. By selecting this feature, that official review request will block the merge from happening even if it technically met the minimum threshold for positive reviews.

The merge will only be blocked if the official review request is made by a whitelisted reviewer.

Dismiss Stale Approvals

This option invalidates outdated approvals when new code is committed (added) which changes the content of the previous pull request (request to merge). In this case, the new pull request will now need to be approved.

Block Merge if Pull Request is Outdated

This option blocks a merge from taking place when the branch the pull request is coming from is behind the main branch. The merge will be blocked when the main branch has newer commits that conflict with the branch from which the user is trying to merge.

Protected File Patterns

This unique feature allows you to protect specific files types that you do not want other users to edit. This can be especially useful for files such as .docs or .yml that are for informational or directional purposes only.

Last updated