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

Steps

Step 2: Configure Project-level Protected Branch Rules

  1. As shown in the following figure, access the Repo page of Test_Project to be configured as a project manager or project administrator.

    Figure 1 Repo page of Test_Project

  2. On the top navigation bar, choose Settings > Policy Settings > Protected Branches and click Create Protected Branch.

    Figure 2 Going to the page for creating a protected branch

  3. As shown in the following figure, configure the master branch as a protected branch. No one but committers can push code to the master branch.

    Figure 3 Configuring protected branch rules

  4. As shown in the following figure, select Force inherit, indicating that all repositories in the project will use the protected branch rule.

    Figure 4 Force inherit

Step 3: Demo on How a Project Manager Failed to Push Files to the Master Branch

  1. As a project manager, check whether you have the commit permission on the code. All repository members need to do this before pushing a code file to the repository.

    As shown in the following figure, access Test_Repo to be pushed, choose Settings > Security Management > Permissions on the top navigation bar, and click Code.

    Figure 5 Checking whether you have the push permission on the code

  2. After confirming that you have the push permission, click Clone/Download > Clone with HTTPS in the upper right corner, and click to copy the HTTPS address of the repository.

    Figure 6 Copying the HTTPS address

  3. Run the clone command to clone Test_Repo to the local host, as shown in the following figure.

    Figure 7 Cloning "Test_Repo" to the local PC

  4. Run the following commands in sequence to go to the repository directory of Test_Repo, create the newfile file, and check whether it is successfully executed.

    cd Test_Repo
    touch newfile
    ll
    Figure 8 Creating newfile and checking whether it is successfully created

  5. Run the following commands in sequence: Run the git add command to add the new file newtext to the staging area. Run the git commit command to submit the change of the file to the Git history and make a note that the commit adds a new file.

    git add newfile
    git commit -m "Add new file"

    As shown in the following figure, if the command output in the red box is displayed, the commit is successful.

    Figure 9 Committing the newfile file to the Git history

  6. Run the git push command to push the latest commit on the local main branch to the main branch of the remote repository.

    git push

    As shown in the following figure, if the information in the red box is displayed, the file fails to be pushed to the master branch because it is a protected branch. Even if you have the permission to push code, you cannot directly push code files to the repository.

    Figure 10 git push failure

Step 4: Demo on How a Committer Merges the Code to the Master Branch

  1. As shown in the following figure, the project manager goes to the Code tab page of Test_Repo, selects the master branch, clicks Create Branch, enters Test for the branch name, and clicks OK.
  2. As shown in the following figure, click Create File for the Test branch.

    Figure 11 Clicking Create File

  3. As shown in the following figure, enter Test_File for the file name and click OK.

    Figure 12 Creating the Test_File file

  4. Click Merge Requests in the top navigation bar and click Create MR. Enter Title, select Use temporary branch, and click OK.

    Figure 13 Creating a merge request

  5. On the Merge Requests tab page, the Merge button in the upper right corner is unavailable. When you click Merge, the error message shown in the following figure is displayed.

    It is because the master branch is a protected branch. Only the committer role can merge code.
    Figure 14 Project manager failing to merge a merge request

  6. As shown in the following figure, Test_02 is a committer. The project manager Test contacts Test_02 to merge the merge request.

    Figure 15 Confirming the committer role

  7. As shown in the following figure, Test_02 goes to the Merge Requests page and merges the merge request of the project manager Test.

    Figure 16 Committer merging the merge request