Skip to main content

Enable protection rules

In Harness Code, you can create branch rules for a single branch or multiple branches in a repository. Branch rules establish criteria for approving and merging PRs, define who can create and delete branches, and more.

Add branch rules

  1. Go to the repository where you want to enable branch rules, and select Settings.
  2. Select the Rules tab.
  3. Select New Branch Rule.
  4. Enter the rule Name and optional Description.
  5. In Target Patterns, specify branches covered by this rule according to branch name globstar patterns, such as string, feature-*, or releases/**. You can also select whether the rule should apply to the default branch (such as main). Patterns can be inclusive or exclusive.
  6. In Bypass List, you can specify users who can bypass this rule.
  7. For each of the Rules, select the rule you want to enable and provide additional specifications, if necessary. For example, if you select Require a minimum number of reviewers, you must specify the minimum number of reviewers.
  8. Select Create Rule.

Available rules

The following rules are available when adding branch rules. Some rules require additional configuration.

RuleAdditional configuration
Block branch creationThis rule doesn't block users in the Bypass List.
Block branch deletionThis rule doesn't block users in the Bypass List.
Require pull requestThis rule doesn't block users in the Bypass List.
Require a minimum number of reviewersYou must specify the minimum number of reviewers.
Require review from code ownersThis rule requires a CODEOWNERS file in your branches. If there is no CODEOWNERS file, Harness can't enforce the rule.
Require approval of new changesThis rule requires that you also enable Require a minimum number of reviewers or Require review from code owners (or both). Without at least one of those additional rules, this rule has no effect.
Require comment resolutionNone.
Require status checks to passYou must specify the checks that must pass.
Limit merge strategiesYou must select the allowed merge strategies.
Auto delete branch on mergeNone.

Toggle rules

You can toggle branch rules on and off.

  1. Go to your repository and select Settings.
  2. Select the Rules tab.
  3. Use the switch next to each rule to enable or disable rules.

Edit or delete rules

  1. Go to your repository and select Settings.
  2. Select the Rules tab.
  3. Locate the rule you want to edit or delete, select More options (), and then select Edit Rule or Delete Rule.