GitLab API

GitlabTool

Actions1095

Branches → putApiV4ProjectsIdRepositoryBranchesBranchProtect

AI-generated

Summary

Protect a specific branch in a GitLab project's repository by updating its protection settings via the GitLab API.

Inputs

  • id (required) — The ID or URL-encoded path of the GitLab project containing the branch to protect.
  • branch (required) — The name of the branch to apply protection settings to.
  • putApiV4ProjectsIdRepositoryBranchesBranchProtect (required) — The request body object specifying the branch protection settings according to the GitLab API's schema for branch protection.
  • baseUrl — Optional base URL of the GitLab instance; defaults to https://gitlab.com if unspecified.

Output shape

a single JSON object representing the updated branch protection settings as returned by the GitLab API

The operation makes a PUT request to /api/v4/projects/{id}/repository/branches/{branch}/protect to update the branch protection and returns the API response. Authentication is required unless explicitly skipped.

Examples

Example 1: Protect the 'main' branch of project ID '42' with specified protection settings

Set 'id' to '42', 'branch' to 'main', and provide the protection settings object in the request body parameter.

Links

Discussion