Search…
Branch Protections
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 with which to work.
Each developer can then 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 admin of a repo can set to control who can edit the specific branch. At Copia our 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.

How To Set Branch Protections

Navigate to the repository for which you want to enable branch protections on one or more branches.
Under the repository name, you'll see several options. Under Settings, select Branches.
Once you're on the branches screen, you have a number of settings you can enable based on the needs of your organization's workflows. You must click on Update Settings to save the features you choose to enable.

Option 1: Choose a default branch.

If you choose one branch as the default branch, then all pull requests and code commits in the selected repo will point towards the branch you've chosen.

Option 2: Enable branch protection settings.

  1. 1.
    Start by choosing the branch you want to protect from the drop-down menu of available branches.
  2. 2.
    Check the box Enable branch protection.
As you go down the page you'll see several different options for different aspects of branch protection.
Enable Branch Protection
  1. 1.
    Disable push - this will prevent all users from being able to push to the branch.
  2. 2.
    Enable Push - any user with a write seat will be able to push an update to the selected branch.
  3. 3.
    Whitelist Restricted Push - this option allows whitelisted users or teams, those you have specifically listed, to push to the branch while blocking any other users from pushing. For this option, make sure to list user names and team names in the below fields.
  4. 4.
    Enable Merge Whitelist - Similar to the above whitelisting option, this 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.
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.
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 feature ties in with the above option to require a minimum number of approvals. After setting your minimum required approvals you'll then 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.
Note that the merge will only be blocked if the change request is made by a whitelisted reviewer.
Block merge on official review request
If one of your whitelisted reviewers determines 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.
Note that 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. Or to put it a different way, when the main branch has newer commits that conflict with the branch from which the user is trying to merge the merge will be blocked.
Protected file patterns (separated using semicolon)
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.