---
title: "PUT /api/v4/projects/{id}/repository/branches/{branch}/protect"
method: PUT
path: "/api/v4/projects/{id}/repository/branches/{branch}/protect"
tags: ["branches"]
---

# PUT /api/v4/projects/{id}/repository/branches/{branch}/protect

`PUT /api/v4/projects/{id}/repository/branches/{branch}/protect`

## Request

- Base URL: `https://gitlab.com`
- URL: `https://gitlab.com/api/v4/projects/{id}/repository/branches/{branch}/protect`
- Auth: none declared

Protect a single branch

## Path parameters

- `id` string, required
- `branch` string, required

## Request body

- PutApiV4ProjectsIdRepositoryBranchesBranchProtect: Protect a single branch
  - `developers_can_push` boolean: Flag if developers can push to that branch
  - `developers_can_merge` boolean: Flag if developers can merge to that branch

## Response `200`

Protect a single branch

- APIEntitiesBranch: API_Entities_Branch model
  - `name` string, required
  - `commit` APIEntitiesCommit, required: API_Entities_Commit model
    - `id` string, required
    - `short_id` string, required
    - `created_at` string, date-time, required
    - `parent_ids` string[], required
    - `title` string, required
    - `message` string, required
    - `author_name` string, required
    - `author_email` string, required
    - `authored_date` string, date-time, required
    - `committer_name` string, required
    - `committer_email` string, required
    - `committed_date` string, date-time, required
    - `trailers` object, required
    - `extended_trailers` object, required
    - `web_url` string, required
  - `merged` boolean, required
  - `protected` boolean, required
  - `developers_can_push` boolean, required
  - `developers_can_merge` boolean, required
  - `can_push` boolean, required
  - `default` boolean, required
  - `web_url` string, required

## Other responses

- `404`: 404 Branch Not Found

---

[API](https://skmtc.dev/gitlab/apis/gitlab-api.md) - [All operations](https://skmtc.dev/gitlab/apis/gitlab-api/llms.txt) - [OpenAPI document](https://skmtc.dev/gitlab/apis/gitlab-api/revisions/b234947ef3f2?raw)
