GitLab Branches API

Use this API to manage [Git branches](https://docs.gitlab.com/user/project/repository/branches/). To change the branch protections configured for a project, use the [protected branches API](https://docs.gitlab.com/api/protected_branches/).

Operations 8

GET /api/v4/projects/{id}/repository/branches List all repository branches #
POST /api/v4/projects/{id}/repository/branches Create a repository branch #
HEAD /api/v4/projects/{id}/repository/branches/{branch} Check if a branch exists #
GET /api/v4/projects/{id}/repository/branches/{branch} Retrieve a repository branch #
DELETE /api/v4/projects/{id}/repository/branches/{branch} Delete a repository branch #
PUT /api/v4/projects/{id}/repository/branches/{branch}/protect Protect a single branch #
PUT /api/v4/projects/{id}/repository/branches/{branch}/unprotect Unprotect a single branch #
DELETE /api/v4/projects/{id}/repository/merged_branches Delete all merged branches #

Documentation

📖
Documentation
https://docs.gitlab.com/api/openapi/
📖
Documentation
https://docs.gitlab.com/api/issues/
📖
Authentication
https://docs.gitlab.com/api/rest/authentication/
📖
Documentation
https://docs.gitlab.com/api/merge_requests/
📖
Documentation
https://docs.gitlab.com/api/pipelines/
📖
Documentation
https://docs.gitlab.com/api/jobs/
📖
Documentation
https://docs.gitlab.com/api/runners/
📖
Documentation
https://docs.gitlab.com/api/users/
📖
Documentation
https://docs.gitlab.com/api/repositories/
📖
Documentation
https://docs.gitlab.com/api/commits/
📖
Documentation
https://docs.gitlab.com/api/branches/
📖
Documentation
https://docs.gitlab.com/api/tags/
📖
Documentation
https://docs.gitlab.com/api/releases/
📖
Documentation
https://docs.gitlab.com/api/environments/
📖
Documentation
https://docs.gitlab.com/api/deployments/
📖
Documentation
https://docs.gitlab.com/api/pipeline_schedules/
📖
Documentation
https://docs.gitlab.com/api/labels/
📖
Documentation
https://docs.gitlab.com/api/milestones/
📖
Documentation
https://docs.gitlab.com/api/notes/
📖
Documentation
https://docs.gitlab.com/api/snippets/
📖
Documentation
https://docs.gitlab.com/api/packages/
📖
Documentation
https://docs.gitlab.com/api/container_registry/
📖
Documentation
https://docs.gitlab.com/api/vulnerabilities/
📖
Documentation
https://docs.gitlab.com/api/deploy_keys/
📖
Documentation
https://docs.gitlab.com/api/protected_branches/
📖
Documentation
https://docs.gitlab.com/api/wikis/
📖
Documentation
https://docs.gitlab.com/api/events/
📖
Documentation
https://docs.gitlab.com/api/search/
📖
Documentation
https://docs.gitlab.com/api/namespaces/
📖
Documentation
https://docs.gitlab.com/api/groups/
📖
Documentation
https://docs.gitlab.com/api/projects/
📖
Documentation
https://docs.gitlab.com/api/applications/
📖
Documentation
https://docs.gitlab.com/api/avatar/
📖
Documentation
https://docs.gitlab.com/api/broadcast_messages/
📖
Documentation
https://docs.gitlab.com/api/bulk_imports/
📖
Documentation
https://docs.gitlab.com/api/settings/
📖
Documentation
https://docs.gitlab.com/api/metadata/
📖
Documentation
https://docs.gitlab.com/api/version/
📖
Documentation
https://docs.gitlab.com/api/rest/
📖
APIReference
https://docs.gitlab.com/api/api_resources/
📖
RateLimits
https://docs.gitlab.com/security/rate_limits/
📖
Documentation
https://docs.gitlab.com/api/oauth2/
📖
Authentication
https://docs.gitlab.com/integration/oauth_provider/
📖
Documentation
https://docs.gitlab.com/user/project/integrations/webhooks.html
📖
APIReference
https://docs.gitlab.com/api/project_webhooks/

Specifications

Schemas & Data

📊
JSONSchema
https://artifacts.apis.io/gitlab/json-schema/gitlab-put-api-v4-application-settings-request-schema.json
📊
JSONSchema
https://artifacts.apis.io/gitlab/json-schema/gitlab-apientities-geo-node-status-schema.json
📊
JSONSchema
https://artifacts.apis.io/gitlab/json-schema/gitlab-apientities-geo-site-status-schema.json
📊
JSONSchema
https://artifacts.apis.io/gitlab/json-schema/gitlab-apientities-application-setting-schema.json
📊
JSONSchema
https://artifacts.apis.io/gitlab/json-schema/gitlab-post-api-v4-geo-status-request-schema.json
📊
JSONSchema
https://artifacts.apis.io/gitlab/json-schema/gitlab-put-api-v4-projects-id-request-schema.json
📊
JSONSchema
https://artifacts.apis.io/gitlab/json-schema/gitlab-api-entities-cluster-schema.json
📊
JSONSchema
https://artifacts.apis.io/gitlab/json-schema/gitlab-api-entities-batched-background-migration-schema.json
📊
JSONSchema
https://artifacts.apis.io/gitlab/json-schema/gitlab-api-entities-ci-variable-schema.json
📊
JSONSchema
https://artifacts.apis.io/gitlab/json-schema/gitlab-api-entities-dictionary-table-schema.json
📊
JSONSchema
https://artifacts.apis.io/gitlab/json-schema/gitlab-api-entities-plan-limit-schema.json
📊
JSONSchema
https://artifacts.apis.io/gitlab/json-schema/gitlab-api-entities-appearance-schema.json
📊
JSONSchema
https://artifacts.apis.io/gitlab/json-schema/gitlab-api-entities-avatar-schema.json
📊
JSONSchema
https://artifacts.apis.io/gitlab/json-schema/gitlab-api-entities-bulk-imports-schema.json
📊
JSONSchema
https://artifacts.apis.io/gitlab/json-schema/gitlab-api-entities-bulk-import-schema.json
📊
JSONSchema
https://artifacts.apis.io/gitlab/json-schema/gitlab-api-entities-metadata-schema.json

Other Resources

Work with this as data

Every API here is available over the APIs.io API and to AI agents over MCP.

MCP server

One button, every client — Claude, Cursor, VS Code and the rest.

https://apis.io/mcp

Tools for apis

7 MCP tools reach this
  • find_apisBrowse and filter every API in the catalog.
  • get_api_artifactsOne API's artifacts, grouped by type.
  • get_openapiThe primary OpenAPI for this API.
  • find_similar_apisAPIs that look like this one.
  • apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.
  • resolveTurn a domain, URL or GitHub org into the provider it belongs to.
  • find_cohortsEvery scored population of providers in the catalog.
All 92 tools →

Call it yourself

curl for this page
This API
curl "https://apis.io/api/v1/apis/gitlab:gitlab-branches-api"
All apis
curl "https://apis.io/api/v1/apis?limit=25"

Calls without X-API-Key need no key. Calls with it need a paid plan — get a key.

Get an API key

Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. See our Privacy Policy and Terms.

A second provider on the same verified email joins the account you already have.

OpenAPI Specification

gitlab-branches-api-openapi.yml Raw ↑
openapi: 3.2.0
info:
  title: GitLab REST Branches API
  description: GitLab REST API used to interact with a GitLab installation.
  termsOfService: https://handbook.gitlab.com/handbook/legal/api-terms/
  version: '19.6'
  license:
    name: CC BY-SA 4.0
    url: https://gitlab.com/gitlab-org/gitlab/-/blob/master/LICENSE
    x-gitlab-description: The license applies to the OpenAPI specification document itself. For terms governing use of the GitLab API, see the termsOfService field.
servers:
- url: https://{hostname}
  description: GitLab REST API
  variables:
    hostname:
      default: gitlab.com
      description: Your GitLab instance hostname
security:
- http: []
- oauth2: []
- apiKey: []
tags:
- name: Branches
  description: 'Use this API to manage Git branches.


    To change the branch protections configured for a project, use the protected branches API.'
  x-displayName: Branches
  externalDocs:
    url: https://docs.gitlab.com/api/branches/
paths:
  /api/v4/projects/{id}/repository/branches:
    get:
      operationId: getApiV4ProjectsIdRepositoryBranches
      summary: List all repository branches
      description: Lists all repository branches from a specified project, sorted alphabetically by name. Search by name, or use regular expressions to find specific branch patterns. Returns detailed information about the branch, including its protection status, merge status, and commit details.
      tags:
      - Branches
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/APIEntitiesBranch'
        '404':
          description: 404 Project Not Found
        '400':
          description: Bad Request
      parameters:
      - name: id
        required: true
        description: ID or URL-encoded path of the project.
        schema:
          oneOf:
          - type: string
          - type: integer
        in: path
      - name: page
        required: false
        description: Page number of results to retrieve.
        schema:
          type: integer
          default: 1
        in: query
        example: 1
      - name: per_page
        required: false
        description: Number of items to list per page.
        schema:
          type: integer
          default: 20
        in: query
        example: 20
      - name: search
        required: false
        description: Return branches containing the search string. Use `^term` to find branches that begin with `term`, and `term$` to find branches that end with `term`.
        schema:
          type:
          - string
          - 'null'
        in: query
      - name: regex
        required: false
        description: Return branches with names matching an [RE2](https://github.com/google/re2/wiki/Syntax) regular expression. Cannot be used together with `search`.
        schema:
          type:
          - string
          - 'null'
        in: query
      - name: sort
        required: false
        description: Sort results by the specified field and direction.
        schema:
          type:
          - string
          - 'null'
          enum:
          - name_asc
          - updated_asc
          - updated_desc
          - null
        in: query
      - name: page_token
        required: false
        description: Name of the branch to start the pagination from. Used for keyset pagination.
        schema:
          type:
          - string
          - 'null'
        in: query
    post:
      operationId: postApiV4ProjectsIdRepositoryBranches
      summary: Create a repository branch
      description: Creates a branch in the repository.
      tags:
      - Branches
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/APIEntitiesBranch'
        '400':
          description: Branch already exists
        '404':
          description: Not Found
      parameters:
      - name: id
        required: true
        description: ID or URL-encoded path of the project.
        schema:
          oneOf:
          - type: string
          - type: integer
        in: path
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/postApiV4ProjectsIdRepositoryBranchesRequest'
  /api/v4/projects/{id}/repository/branches/{branch}:
    head:
      operationId: headApiV4ProjectsIdRepositoryBranchesBranch
      summary: Check if a branch exists
      description: Checks whether a branch exists in the repository, without returning the branch.
      tags:
      - Branches
      responses:
        '204':
          description: No Content
        '404':
          description: Not Found
        '400':
          description: Bad Request
      parameters:
      - name: id
        required: true
        description: ID or URL-encoded path of the project.
        schema:
          oneOf:
          - type: string
          - type: integer
        in: path
      - name: branch
        required: true
        description: Name of the branch.
        schema:
          type: string
        in: path
    get:
      operationId: getApiV4ProjectsIdRepositoryBranchesBranch
      summary: Retrieve a repository branch
      description: Retrieves a specified project repository branch.
      tags:
      - Branches
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/APIEntitiesBranch'
        '404':
          description: Project Not Found
        '400':
          description: Bad Request
      parameters:
      - name: id
        required: true
        description: ID or URL-encoded path of the project.
        schema:
          oneOf:
          - type: string
          - type: integer
        in: path
      - name: branch
        required: true
        description: Name of the branch.
        schema:
          type: string
        in: path
    delete:
      operationId: deleteApiV4ProjectsIdRepositoryBranchesBranch
      summary: Delete a repository branch
      description: Deletes a specified branch from the repository.
      tags:
      - Branches
      responses:
        '204':
          description: No Content
        '404':
          description: Branch Not Found
        '400':
          description: Bad Request
      parameters:
      - name: id
        required: true
        description: ID or URL-encoded path of the project.
        schema:
          oneOf:
          - type: string
          - type: integer
        in: path
      - name: branch
        required: true
        description: Name of the branch.
        schema:
          type: string
        in: path
  /api/v4/projects/{id}/repository/branches/{branch}/protect:
    put:
      operationId: putApiV4ProjectsIdRepositoryBranchesBranchProtect
      summary: Protect a single branch
      description: Protects a single branch, or updates its protection if it is already protected. Only users with the Maintainer role can push or merge unless `developers_can_push` or `developers_can_merge` is `true`.
      tags:
      - Branches
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/APIEntitiesBranch'
        '404':
          description: 404 Branch Not Found
        '400':
          description: Bad Request
      parameters:
      - name: id
        required: true
        description: ID or URL-encoded path of the project.
        schema:
          oneOf:
          - type: string
          - type: integer
        in: path
      - name: branch
        required: true
        description: Name of the branch.
        schema:
          type: string
        in: path
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/putApiV4ProjectsIdRepositoryBranchesBranchProtectRequest'
  /api/v4/projects/{id}/repository/branches/{branch}/unprotect:
    put:
      operationId: putApiV4ProjectsIdRepositoryBranchesBranchUnprotect
      summary: Unprotect a single branch
      description: Removes the protection from a single protected branch.
      tags:
      - Branches
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/APIEntitiesBranch'
        '404':
          description: 404 Branch Not Found
        '400':
          description: Bad Request
      parameters:
      - name: id
        required: true
        description: ID or URL-encoded path of the project.
        schema:
          oneOf:
          - type: string
          - type: integer
        in: path
      - name: branch
        required: true
        description: Name of the branch.
        schema:
          type: string
        in: path
  /api/v4/projects/{id}/repository/merged_branches:
    delete:
      operationId: deleteApiV4ProjectsIdRepositoryMergedBranches
      summary: Delete all merged branches
      description: Deletes all branches that are merged into the default branch for a project.
      tags:
      - Branches
      responses:
        '202':
          description: 202 Accepted
        '404':
          description: 404 Project Not Found
        '400':
          description: Bad Request
      parameters:
      - name: id
        required: true
        description: ID or URL-encoded path of the project.
        schema:
          oneOf:
          - type: string
          - type: integer
        in: path
components:
  schemas:
    APIEntitiesCommit:
      type: object
      properties:
        id:
          type: string
          example: 2695effb5807a22ff3d138d593fd856244e155e7
        short_id:
          type: string
          example: 2695effb
        created_at:
          type: string
          format: date-time
          example: '2017-07-26T11:08:53.000+02:00'
        parent_ids:
          type: array
          example:
          - 2a4b78934375d7f53875269ffd4f45fd83a84ebe
          items:
            type: string
        title:
          type: string
          example: Initial commit
        message:
          type: string
          example: Initial commit
        author_name:
          type: string
          example: John Smith
        author_email:
          type: string
          example: john@example.com
        authored_date:
          type: string
          format: date-time
          example: '2012-05-28T04:42:42-07:00'
        committer_name:
          type: string
          example: Jack Smith
        committer_email:
          type: string
          example: jack@example.com
        committed_date:
          type: string
          format: date-time
          example: '2012-05-28T04:42:42-07:00'
        trailers:
          type: object
          example:
            Merged-By: Jane Doe janedoe@gitlab.com
        extended_trailers:
          type: object
          example:
            Signed-off-by:
            - John Doe <johndoe@gitlab.com>
            - Jane Doe <janedoe@gitlab.com>
        web_url:
          type: string
          example: https://gitlab.example.com/janedoe/gitlab-foss/-/commit/ed899a2f4b50b4370feeea94676502b42383c746
    APIEntitiesBranch:
      type: object
      properties:
        name:
          type: string
          example: master
        commit:
          $ref: '#/components/schemas/APIEntitiesCommit'
        merged:
          type: boolean
          example: true
        protected:
          type: boolean
          example: true
        developers_can_push:
          type: boolean
          example: true
        developers_can_merge:
          type: boolean
          example: true
        can_push:
          type: boolean
          example: true
        default:
          type: boolean
          example: true
        web_url:
          type: string
          example: https://gitlab.example.com/Commit921/the-dude/-/tree/master
    postApiV4ProjectsIdRepositoryBranchesRequest:
      type: object
      properties:
        branch:
          type:
          - string
          - 'null'
          description: Name of the branch.
        ref:
          type:
          - string
          - 'null'
          description: Branch name or commit SHA to create the branch from.
      required:
      - branch
      - ref
    putApiV4ProjectsIdRepositoryBranchesBranchProtectRequest:
      type: object
      properties:
        developers_can_push:
          type:
          - boolean
          - 'null'
          description: If `true`, allows developers to push to the branch.
        developers_can_merge:
          type:
          - boolean
          - 'null'
          description: If `true`, allows developers to merge to the branch.
  securitySchemes:
    http:
      type: http
      scheme: bearer
    oauth2:
      type: oauth2
      flows:
        authorizationCode:
          authorizationUrl: https://gitlab.com/oauth/authorize
          tokenUrl: https://gitlab.com/oauth/token
          refreshUrl: https://gitlab.com/oauth/token
          scopes:
            api: Grants complete read/write access to the API, including all groups and projects, the container registry, the dependency proxy, and the package registry.
            read_api: Grants read access to the API, including all groups and projects, the container registry, and the package registry.
            read_user: Grants read-only access to your profile through the /user API endpoint, which includes username, public email, and full name. Also grants access to read-only API endpoints under /users.
            create_runner: Grants create access to the runners.
            manage_runner: Grants access to manage the runners.
            k8s_proxy: Grants permission to perform Kubernetes API calls using the agent for Kubernetes.
            self_rotate: Grants permission for token to rotate itself.
            mcp: Grants read-write access to remote Model Context Protocol (MCP) server for tools execution.
            mcp_orbit: Grants access to the Orbit Knowledge Graph MCP server for graph queries and schema retrieval.
    apiKey:
      type: apiKey
      name: PRIVATE-TOKEN
      in: header