Updated on 2025-07-22 GMT+08:00

Overview

Set up protected branch rules during collaborative coding to enhance code quality, safeguard branches, and boost teamwork for reliable, secure code delivery.

This section provides an overview of the best practices including:

Application Scenarios

Developing code without protected branch rules may interrupt your development pace and even delivery.

  • Merging unreviewed code into main branches may cause defects and further incur online faults and higher O&M costs.
  • Key branches are forcibly pushed and overwritten, causing historical records to be lost. As a result, problems are difficult to trace, affecting fault locating and compliance audit.
  • CI/CD process is not strictly followed. As a result, bad code enters the production environment, which may cause version rollback or user complaints.
  • Unstandardized collaboration and random branch merge cause frequent code conflicts and disrupted version iteration.

Protected branch rules can help you solve the following pain points:

  • Core branches (such as master): No role is allowed to push code to core branches. Only compliant code can be brought online, reducing production risks.
  • Permission control: Only authorized members can merge key branches to block unqualified code and maintain enterprise security standards.

Advantages

Setting protected branch rules for key code branches in CodeArts Repo, your team will enjoy the following core advantages:

  • Prevent direct code push. Submitting changes via merge requests can shield developers from directly pushing code to the protected branches, facilitating code review.
  • Ensure code quality. Merging merge requests by authorized members improves code maintainability.
  • Control permissions and compliance. Allowing authorized members to merge code strengthens enterprises' hierarchical management and helps trace code change sources.
  • Reduce conflicts and improve collaboration efficiency. Prohibiting direct pushes to protected branches minimizes code conflicts caused by members' unstandardized operations and helps new members quickly get started by standardizing the push process.

Constraints

Only a project manager or project administrator can configure protected branch rules for all repositories in a project. Refer to the following steps:

  1. As shown in the following figure, go to the Repo page of Test_Project to be configured.

    Figure 1 Repo page of Test_Project

  2. In the left navigation pane, choose Settings > Members. As shown in the following figure, the current user is a project manager and project administrator. Therefore, the current user has the permission to configure protected branch rules for the project.

    Figure 2 Member view page