How to changes settings on multiple repos

How to Change Settings on Multiple Repositories in GitLab?

I have several GitLab repositories, and I’d like to apply specific settings across all of them. Here are the use cases I need to address:

  1. Branch Defaults: I want to set the default branch to master.
  2. Push Rules: I need to enforce rules such as rejecting unsigned commits, preventing secret files from being pushed, and allowing only emails ending with “”
  3. Protected Branches: I’d like to protect the master branch, ensuring that merging requires a merge commit with various checks and approvals.
  4. Merge Request Approvals: Changes to protected branches should require 2 approvals from Developers and 1 from Maintainers.

What’s the best way to achieve this across multiple repositories? Any guidance or best practices would be appreciated!

To change settings on multiple repositories, I suggest using the GitLab REST API with the scripting/programming language of your choice to do this programmatically:

  1. Branch Defaults: Edit project API (PUT /projects/:id?default_branch=master)
  2. Push Rules : Edit project push rule API (PUT /projects/:id/push_rule?reject_unsigned_commits=true)
  3. Protected Branches: Protect repository branches API (POST /projects/:id/protected_branches?name=master&push_access_level=0)
  4. Merge Request Approvals: Merge Request Approvals API at the Group or Project level (POST /projects/:id/approval_rules?approvals_required=2)