Updated on 2023-07-25 GMT+08:00

Protected Branches

To configure protected branches, you can choose Settings > Policy Settings > Protected Branches on the repository details page.

The settings take effect only for the repository configured.

Only the repository administrators and owners can view this tab page and configure protected branches.

Functions of Protected Branches

  • Ensure branch security and allow developers to use MRs to merge code.
  • Prevent non-administrators from pushing codes.
  • Prevent all forcibly push to this branch.
  • Prevent anyone from deleting this branch.

When you create a repository, the repository automatically sets the default branch (generally master) as the protection branch to ensure repository security.

After you set a protected branch, the protected branch cannot be used as the target branch for code merging.

Editing Protected Branches

You can set a protected branch. The procedure is as follows:
  • Click Create Protected Branch. In the Added Protected Branch dialog box, select a branch from the drop-down list or manually enter a branch name or wildcard character, select the corresponding permissions or assign permissions to users, and click OK.
  • Click to modify the configuration of the protected branch.
  • Click to delete the protected branch.

  • Configure the whitelist: To assign permissions to one or more members of an unauthorized role, you can select Push and Merge under Members and click the drop-down list to add the members to the trustlist.

  • Only developers and users with permissions higher than developers have the Can push and Can merge permissions.
  • If Administrator, Committer, and Developer are selected for Can push, all these roles have the permissions. In this case, you do not need to select Can push or Can merge under Members.
  • You can create, edit, and delete protected branches in batches.