GitLab API icon

GitLab API

Gitlab

Actions1062

Branches → putApiV4ProjectsIdRepositoryBranchesBranchProtect

AI-generated

Summary

Protect a specific branch in a GitLab project by sending a PUT request to the GitLab API endpoint for branch protection.

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 protect.
  • Request Body (required) — The protection settings and options to apply to the branch, structured according to the GitLab API's branch protection schema.
  • Skip Authentication — Optionally skip authentication for the request (default is false).
  • baseUrl — The base URL for the GitLab instance (default is https://gitlab.com).

Output shape

a JSON object representing the protected branch's updated details as returned by the GitLab API

The response conforms to the GitLab API's branch object format after protection updates. Authentication via configured credentials is applied unless Skip Authentication is enabled.

Examples

Example 1: Protect the 'main' branch in project '12345' with specific protection rules.

Set 'Id' to '12345', 'Branch' to 'main', and provide the desired protection settings JSON in the request body, then execute the operation to update branch protection settings.

Links

Discussion