After creating a new project in GitLab, add a member to the project, but give the developer role. If the added member needs to push and upload the code on the trunk, it will not succeed, because the default trunk is protected and the developer role cannot push and merge the code. Let’s see how to solve this problem without changing the permissions of member roles

Tools/materials

  • gitlab

Methods/steps

  1. Open a browser to the web page address of your Gitlag service, log in as an administrator or as the account that created the project, and then go to the specified project page

  2. On the right as shown, click on the select Protected Branches option

  3. As you can see from the figure, no branch protection has been set up before, but the master trunk is protected by default, and push and merge code is not allowed by default

  4. If you just want to cancel the protection, you just need to click the Unprotect button to remove the protection. When you need push code but cannot merge, you need to check Deverlopers can push individually, but the protected code is not checked save button, you need to cancel the protection first. Then re-check click protection above

  5. With the default master unprotected, you can reproduce the master option as shown, then check the Developer can Push check box, and then click Protect

  6. As shown in the figure, the master trunk is readded to the protected list, but the Developer role users can push code instead of merge code

  7. The default trunk is protected, but we can also set other branches to the protected list in a similar way

  8. The default trunk does not, but branch code can be pushed. If there is no master branch, one of the other branches will default to the trunk