How to allow people to push directly to the default branch¶
Projects created by the GitLab project factory protect the default branch so that nobody can push straight to it. Changes go through a reviewed merge request, as described in our use of git.
For experiment or prototype projects, where a merge request for every change gets in the way, you can name people who may push directly to the default branch.
Warning
Only do this for non-production or experiment projects. Anything that deploys to production, or that other services rely on, should keep the merge request flow so that changes are reviewed and pipelines run before they land. If an experiment becomes a real product, remove the setting.
Add the setting¶
In the project factory, open your product's .tfvars file in product-vars/ and add
users_allowed_to_push_to_default_branch to the project, listing people by username:
projects = {
"experiments-my-prototype" = {
# ...
users_allowed_to_push_to_default_branch = ["crsid1", "crsid2"]
}
}
Open a merge request against the project factory with the change. Once it is merged and applied, the people listed can push to the default branch.
Don't add people by hand in the GitLab settings. The project factory treats that as drift: the daily check flags it, and the next apply for your product removes it.
Things to check¶
- Each person must already have at least Developer access to the project, either directly or through a group. Otherwise GitLab rejects the branch protection rule and the apply fails.
- The list is for people only. Bot users go in
bots_allowed_to_push_to_default_branch, which takes numeric user IDs. The project factory rejects a bot in the people list, and a person in the bot list. - Remove people from the list when they no longer need it, for example when they move team.