[Skip to main content](https://docs.gitlab.com/api/repositories/#skipTarget) [Go to GitLab Docs homepage](https://docs.gitlab.com/)
`/`
[What's new?](https://about.gitlab.com/releases/whats-new/)
English
  * Language
  * English
  * 日本語


v18.10
  *     * [18.10 (not yet released)](https://docs.gitlab.com/api/repositories/)
  *     * [18.9 (recently released)](https://docs.gitlab.com/18.9/api/repositories/)
    * [18.8](https://docs.gitlab.com/18.8/api/repositories/)
    * [18.7](https://archives.docs.gitlab.com/18.7/api/repositories/)
  *     * [17.11](https://archives.docs.gitlab.com/17.11/api/repositories/)
    * [16.11](https://archives.docs.gitlab.com/16.11/ee/api/repositories.html)
  *     * [Archives](https://docs.gitlab.com/archives)


Select theme and layout
  * Light mode
  * Dark mode
  * Auto


  * Fixed width
  * Fluid width


[What's new?](https://about.gitlab.com/releases/whats-new/) [Get free trial](https://gitlab.com/-/trial_registrations/new?glm_source=docs.gitlab.com&amp;glm_content=navigation-cta-docs)
Toggle menu
  * [Use GitLab](https://docs.gitlab.com/user/)
  * [GitLab Duo](https://docs.gitlab.com/user/gitlab_duo/)
  * [Extend](https://docs.gitlab.com/api/)
  * [Install](https://docs.gitlab.com/install/)
  * [Administer](https://docs.gitlab.com/administration/)
  * [Subscribe](https://docs.gitlab.com/subscriptions/)
  * [Contribute](https://docs.gitlab.com/development/)
  * [Solutions](https://docs.gitlab.com/solutions/)


Select a topicUse GitLab GitLab Duo Extend Install Administer Subscribe Contribute Solutions
[Getting started](https://docs.gitlab.com/api/get_started/get_started_extending/)
[Tutorials](https://docs.gitlab.com/tutorials/develop/)
[Integrations](https://docs.gitlab.com/integration/)
[Webhooks](https://docs.gitlab.com/user/project/integrations/webhooks/)
[REST API](https://docs.gitlab.com/api/rest/)
[Resources](https://docs.gitlab.com/api/api_resources/)
[.gitignore (templates)](https://docs.gitlab.com/api/templates/gitignores/)
[.gitlab-ci.yml (templates)](https://docs.gitlab.com/api/templates/gitlab_ci_ymls/)
[Access requests](https://docs.gitlab.com/api/access_requests/)
[Agent for Kubernetes](https://docs.gitlab.com/api/cluster_agents/)
[AI Catalog admin](https://docs.gitlab.com/api/admin/ai_catalog/)
[Alert management](https://docs.gitlab.com/api/alert_management_alerts/)
[Application appearance](https://docs.gitlab.com/api/appearance/)
[Application settings](https://docs.gitlab.com/api/settings/)
[Application statistics](https://docs.gitlab.com/api/statistics/)
[Applications](https://docs.gitlab.com/api/applications/)
[Attestations](https://docs.gitlab.com/api/attestations/)
[Audit events](https://docs.gitlab.com/api/audit_events/)
[Avatar](https://docs.gitlab.com/api/avatar/)
[Branches](https://docs.gitlab.com/api/branches/)
[Broadcast messages](https://docs.gitlab.com/api/broadcast_messages/)
[Cluster discovery (certificate-based) (deprecated)](https://docs.gitlab.com/api/cluster_discovery/)
[Code Suggestions](https://docs.gitlab.com/api/code_suggestions/)
[Commits](https://docs.gitlab.com/api/commits/)
[Compliance and policy settings](https://docs.gitlab.com/api/compliance_policy_settings/)
[Composer](https://docs.gitlab.com/api/packages/composer/)
[Conan v1](https://docs.gitlab.com/api/packages/conan_v1/)
[Conan v2](https://docs.gitlab.com/api/packages/conan_v2/)
[Container registry](https://docs.gitlab.com/api/container_registry/)
[Container repository protection rules](https://docs.gitlab.com/api/container_repository_protection_rules/)
[Container registry protection tag rules](https://docs.gitlab.com/api/container_registry_protection_tag_rules/)
[Container virtual registry](https://docs.gitlab.com/api/container_virtual_registries/)
[Custom attributes](https://docs.gitlab.com/api/custom_attributes/)
[Database migrations](https://docs.gitlab.com/api/database_migrations/)
[Data management](https://docs.gitlab.com/api/admin/data_management/)
[Debian](https://docs.gitlab.com/api/packages/debian/)
[Debian group distributions](https://docs.gitlab.com/api/packages/debian_group_distributions/)
[Debian project distributions](https://docs.gitlab.com/api/packages/debian_project_distributions/)
[Dependencies](https://docs.gitlab.com/api/dependencies/)
[Dependency list export](https://docs.gitlab.com/api/dependency_list_export/)
[Dependency Proxy](https://docs.gitlab.com/api/dependency_proxy/)
[Deploy keys](https://docs.gitlab.com/api/deploy_keys/)
[Deploy tokens](https://docs.gitlab.com/api/deploy_tokens/)
[Deployments](https://docs.gitlab.com/api/deployments/)
[Discussions](https://docs.gitlab.com/api/discussions/)
[Dockerfile (templates)](https://docs.gitlab.com/api/templates/dockerfiles/)
[DORA4 metrics](https://docs.gitlab.com/api/dora/metrics/)
[Emoji reactions](https://docs.gitlab.com/api/emoji_reactions/)
[Environments](https://docs.gitlab.com/api/environments/)
[Epics (deprecated)](https://docs.gitlab.com/api/epics/)
[Error tracking](https://docs.gitlab.com/api/error_tracking/)
[Events](https://docs.gitlab.com/api/events/)
[Experiments](https://docs.gitlab.com/api/experiments/)
[External status checks](https://docs.gitlab.com/api/status_checks/)
[Feature flags](https://docs.gitlab.com/api/feature_flags/)
[Feature flag user lists](https://docs.gitlab.com/api/feature_flag_user_lists/)
[Freeze periods](https://docs.gitlab.com/api/freeze_periods/)
[Geo nodes (deprecated)](https://docs.gitlab.com/api/geo_nodes/)
[Geo sites](https://docs.gitlab.com/api/geo_sites/)
[GitLab Duo Chat completions](https://docs.gitlab.com/api/chat/)
[GitLab Pages](https://docs.gitlab.com/api/pages/)
[GLQL](https://docs.gitlab.com/api/glql/)
[Go Proxy](https://docs.gitlab.com/api/packages/go_proxy/)
[Google Cloud integration](https://docs.gitlab.com/api/google_cloud_integration/)
[Groups](https://docs.gitlab.com/api/groups/)
[Helm](https://docs.gitlab.com/api/packages/helm/)
[Import](https://docs.gitlab.com/api/import/)
[Instance CI/CD variables](https://docs.gitlab.com/api/instance_level_ci_variables/)
[Invitations](https://docs.gitlab.com/api/invitations/)
[Issues](https://docs.gitlab.com/api/issues/)
[Issues (epic) (deprecated)](https://docs.gitlab.com/api/epic_issues/)
[Issues statistics](https://docs.gitlab.com/api/issues_statistics/)
[Jobs](https://docs.gitlab.com/api/jobs/)
[Job artifacts](https://docs.gitlab.com/api/job_artifacts/)
[Job token scopes](https://docs.gitlab.com/api/project_job_token_scopes/)
[Keys](https://docs.gitlab.com/api/keys/)
[License](https://docs.gitlab.com/api/license/)
[Licenses (templates)](https://docs.gitlab.com/api/templates/licenses/)
[Linked epics (deprecated)](https://docs.gitlab.com/api/linked_epics/)
[Links (issue)](https://docs.gitlab.com/api/issue_links/)
[Links (epic) (deprecated)](https://docs.gitlab.com/api/epic_links/)
[Lint .gitlab-ci.yml](https://docs.gitlab.com/api/lint/)
[Markdown](https://docs.gitlab.com/api/markdown/)
[Maven](https://docs.gitlab.com/api/packages/maven/)
[Maven virtual registry](https://docs.gitlab.com/api/maven_virtual_registries/)
[Member roles](https://docs.gitlab.com/api/member_roles/)
[Merge request approvals](https://docs.gitlab.com/api/merge_request_approvals/)
[Merge request approval settings](https://docs.gitlab.com/api/merge_request_approval_settings/)
[Merge request context commits](https://docs.gitlab.com/api/merge_request_context_commits/)
[Merge requests](https://docs.gitlab.com/api/merge_requests/)
[Merge trains](https://docs.gitlab.com/api/merge_trains/)
[Metadata](https://docs.gitlab.com/api/metadata/)
[Model registry](https://docs.gitlab.com/api/model_registry/)
[Namespaces](https://docs.gitlab.com/api/namespaces/)
[Notes (comments)](https://docs.gitlab.com/api/notes/)
[Notification settings](https://docs.gitlab.com/api/notification_settings/)
[npm](https://docs.gitlab.com/api/packages/npm/)
[NuGet](https://docs.gitlab.com/api/packages/nuget/)
[Organizations](https://docs.gitlab.com/api/organizations/)
[Packages](https://docs.gitlab.com/api/packages/)
[Pages domains](https://docs.gitlab.com/api/pages_domains/)
[Personal access tokens](https://docs.gitlab.com/api/personal_access_tokens/)
[Pipeline schedules](https://docs.gitlab.com/api/pipeline_schedules/)
[Pipeline trigger tokens](https://docs.gitlab.com/api/pipeline_triggers/)
[Pipelines](https://docs.gitlab.com/api/pipelines/)
[Plan limits](https://docs.gitlab.com/api/plan_limits/)
[Product analytics](https://docs.gitlab.com/api/product_analytics/)
[Projects](https://docs.gitlab.com/api/projects/)
[PyPI](https://docs.gitlab.com/api/packages/pypi/)
[Repositories](https://docs.gitlab.com/api/repositories/)
[Repository files](https://docs.gitlab.com/api/repository_files/)
[Repository submodules](https://docs.gitlab.com/api/repository_submodules/)
[Resource group](https://docs.gitlab.com/api/resource_groups/)
[Resource iteration events](https://docs.gitlab.com/api/resource_iteration_events/)
[Resource label events](https://docs.gitlab.com/api/resource_label_events/)
[Resource milestone events](https://docs.gitlab.com/api/resource_milestone_events/)
[Resource state events](https://docs.gitlab.com/api/resource_state_events/)
[Resource weight events](https://docs.gitlab.com/api/resource_weight_events/)
[Ruby gems](https://docs.gitlab.com/api/packages/rubygems/)
[Runners](https://docs.gitlab.com/api/runners/)
[Runner controllers](https://docs.gitlab.com/api/runner_controllers/)
[Runner controller tokens](https://docs.gitlab.com/api/runner_controller_tokens/)
[Search](https://docs.gitlab.com/api/search/)
[Search migrations](https://docs.gitlab.com/api/search_admin/)
[Secure files](https://docs.gitlab.com/api/secure_files/)
[Service accounts](https://docs.gitlab.com/api/service_accounts/)
[Service Ping](https://docs.gitlab.com/api/usage_data/)
[Sidekiq metrics](https://docs.gitlab.com/api/sidekiq_metrics/)
[Sidekiq queues](https://docs.gitlab.com/api/admin_sidekiq_queues/)
[Snippet repository storage moves](https://docs.gitlab.com/api/snippet_repository_storage_moves/)
[Snippets](https://docs.gitlab.com/api/snippets/)
[Suggestions](https://docs.gitlab.com/api/suggestions/)
[System hooks](https://docs.gitlab.com/api/system_hooks/)
[Tags](https://docs.gitlab.com/api/tags/)
[Terraform registry](https://docs.gitlab.com/api/packages/terraform-modules/)
[To-Do List](https://docs.gitlab.com/api/todos/)
[Token information](https://docs.gitlab.com/api/admin/token/)
[Topics](https://docs.gitlab.com/api/topics/)
[Users](https://docs.gitlab.com/api/users/)
[Version](https://docs.gitlab.com/api/version/)
[Virtual registries cleanup policies](https://docs.gitlab.com/api/virtual_registries_cleanup_policies/)
[Vulnerabilities](https://docs.gitlab.com/api/vulnerabilities/)
[Vulnerability archive export](https://docs.gitlab.com/api/vulnerability_archive_exports/)
[Vulnerability export](https://docs.gitlab.com/api/vulnerability_exports/)
[Vulnerability findings](https://docs.gitlab.com/api/vulnerability_findings/)
[Web commits](https://docs.gitlab.com/api/web_commits/)
[Authentication](https://docs.gitlab.com/api/rest/authentication/)
[Third-party clients](https://docs.gitlab.com/api/rest/third_party_clients/)
[Deprecations and removals](https://docs.gitlab.com/api/rest/deprecations/)
[OpenAPI](https://docs.gitlab.com/api/openapi/openapi_interactive/)
[Automate storage management](https://docs.gitlab.com/user/storage_management_automation/)
[Troubleshooting](https://docs.gitlab.com/api/rest/troubleshooting/)
[GraphQL API](https://docs.gitlab.com/api/graphql/)
[OAuth 2.0 identity provider API](https://docs.gitlab.com/api/oauth2/)
[GitLab Duo CLI (duo)](https://docs.gitlab.com/user/gitlab_duo_cli/)
[GitLab CLI (glab)](https://docs.gitlab.com/cli/)
[Editor and IDE extensions](https://docs.gitlab.com/editor_extensions/)
/
  1. [GitLab Docs](https://docs.gitlab.com/)
  2. [Extend](https://docs.gitlab.com/api/)
  3. [REST API](https://docs.gitlab.com/api/rest/)
  4. [Resources](https://docs.gitlab.com/api/api_resources/)
  5. [Repositories](https://docs.gitlab.com/api/repositories/)


* * *
# Repositories API
  * Tier: Free, Premium, Ultimate
  * Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated


Use this API to manage [Git repositories](https://docs.gitlab.com/user/project/repository/).
## List all repository trees in a project[](https://docs.gitlab.com/api/repositories/#list-all-repository-trees-in-a-project "Permalink")
Lists all repository files and directories in a specified project. This endpoint can be accessed without authentication if the repository is publicly accessible.
This command provides essentially the same features as the `git ls-tree` command. For more information, refer to the section [Tree Objects](https://git-scm.com/book/en/v2/Git-Internals-Git-Objects.html#_tree_objects) in the Git internals documentation.
GitLab version 17.7 changes the error handling behavior when a requested path is not found. The endpoint now returns a status code `404 Not Found`. Previously, the status code was `200 OK`.
If your implementation relies on receiving a `200` status code with an empty array for missing paths, you must update your error handling to handle the new `404` responses.
```
GET /projects/:id/repository/tree
```

Supported attributes:
Attribute | Type | Required | Description
---|---|---|---
`id` | integer or string | Yes | ID or [URL-encoded path](https://docs.gitlab.com/api/rest/#namespaced-paths) of the project.
`page_token` | string | No | Tree record ID at which to fetch the next page. Used only with keyset pagination.
`pagination` | string | No | If `keyset`, use the [keyset-based pagination method](https://docs.gitlab.com/api/rest/#keyset-based-pagination).
`path` | string | No | Path inside the repository. Used to get content of subdirectories.
`per_page` | integer | No | Number of results to show per page. If not specified, defaults to `20`. For more information, see [Pagination](https://docs.gitlab.com/api/rest/#pagination).
`recursive` | boolean | No | If `true`, get a recursive tree. Default is `false`.
`ref` | string | No | Name of a repository branch or tag. If not specified, uses the default branch.
If successful, returns [`200 OK`](https://docs.gitlab.com/api/rest/troubleshooting/#status-codes) and an array of tree objects.
Example request:
shell
```
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/13083/repository/tree"
```

Example response:
json
```
[
  {
    "id": "a1e8f8d745cc87e3a9248358d9352bb7f9a0aeba",
    "name": "html",
    "type": "tree",
    "path": "files/html",
    "mode": "040000"
  },
  {
    "id": "4535904260b1082e14f867f7a24fd8c21495bde3",
    "name": "images",
    "type": "tree",
    "path": "files/images",
    "mode": "040000"
  },
  {
    "id": "31405c5ddef582c5a9b7a85230413ff90e2fe720",
    "name": "js",
    "type": "tree",
    "path": "files/js",
    "mode": "040000"
  },
  {
    "id": "cc71111cfad871212dc99572599a568bfe1e7e00",
    "name": "lfs",
    "type": "tree",
    "path": "files/lfs",
    "mode": "040000"
  },
  {
    "id": "fd581c619bf59cfdfa9c8282377bb09c2f897520",
    "name": "markdown",
    "type": "tree",
    "path": "files/markdown",
    "mode": "040000"
  },
  {
    "id": "23ea4d11a4bdd960ee5320c5cb65b5b3fdbc60db",
    "name": "ruby",
    "type": "tree",
    "path": "files/ruby",
    "mode": "040000"
  },
  {
    "id": "7d70e02340bac451f281cecf0a980907974bd8be",
    "name": "whitespace",
    "type": "blob",
    "path": "files/whitespace",
    "mode": "100644"
  }
]
```

## Retrieve a blob from a repository[](https://docs.gitlab.com/api/repositories/#retrieve-a-blob-from-a-repository "Permalink")
Retrieves information, such as size and content, about blobs in a repository. Blob content is Base64 encoded. This endpoint can be accessed without authentication, if the repository is publicly accessible.
For blobs larger than 10 MB, this endpoint has a rate limit of 5 requests per minute.
```
GET /projects/:id/repository/blobs/:sha
```

Supported attributes:
Attribute | Type | Required | Description
---|---|---|---
`id` | integer or string | Yes | ID or [URL-encoded path](https://docs.gitlab.com/api/rest/#namespaced-paths) of the project.
`sha` | string | Yes | Blob SHA.
If successful, returns [`200 OK`](https://docs.gitlab.com/api/rest/troubleshooting/#status-codes) and the following response attributes:
Attribute | Type | Description
---|---|---
`content` | string | Base64 encoded blob content.
`encoding` | string | Encoding used for the blob content.
`sha` | string | Blob SHA.
`size` | integer | Size of the blob in bytes.
Example request:
shell
```
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/13083/repository/blobs/79f7bbd25901e8334750839545a9bd021f0e4c83"
```

Example response:
json
```
{
  "size": 1476,
  "encoding": "base64",
  "content": "VGhpcyBpcyBhIGJpbmFyeSBmaWxl",
  "sha": "79f7bbd25901e8334750839545a9bd021f0e4c83"
}
```

## Retrieve raw blob content[](https://docs.gitlab.com/api/repositories/#retrieve-raw-blob-content "Permalink")
Retrieves the raw file contents for a blob, by blob SHA. This endpoint can be accessed without authentication if the repository is publicly accessible.
```
GET /projects/:id/repository/blobs/:sha/raw
```

Supported attributes:
Attribute | Type | Required | Description
---|---|---|---
`id` | integer or string | Yes | ID or [URL-encoded path](https://docs.gitlab.com/api/rest/#namespaced-paths) of the project.
`sha` | string | Yes | Blob SHA.
Example request:
shell
```
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/13083/repository/blobs/79f7bbd25901e8334750839545a9bd021f0e4c83/raw"
```

## Retrieve file archive from a repository[](https://docs.gitlab.com/api/repositories/#retrieve-file-archive-from-a-repository "Permalink")
Retrieves the file archive of the specified repository. This endpoint can be accessed without authentication if the repository is publicly accessible.
For GitLab.com users, this endpoint has a rate limit threshold of 5 requests per minute.
```
GET /projects/:id/repository/archive[.format]
```

`format` is an optional suffix for the archive format, and defaults to `tar.gz`. For example, specifying `archive.zip` sends an archive in ZIP format. Available options are:
  * `bz2`
  * `tar`
  * `tar.bz2`
  * `tar.gz`
  * `tb2`
  * `tbz`
  * `tbz2`
  * `zip`


Supported attributes:
Attribute | Type | Required | Description
---|---|---|---
`id` | integer or string | Yes | ID or [URL-encoded path](https://docs.gitlab.com/api/rest/#namespaced-paths) of the project.
`exclude_paths` | string | No | Comma-separated list of paths to exclude from the archive.
`include_lfs_blobs` | boolean | No | If `true`, LFS objects are included in the archive. When set to `false`, LFS objects are excluded. Default is `true`.
`path` | string | No | Subpath of the repository to download. If an empty string, defaults to the whole repository.
`sha` | string | No | Commit SHA to download. Accepts a tag, branch reference, or SHA. If not specified, defaults to the tip of the default branch.
Example request:
shell
```
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.com/api/v4/projects/<project_id>/repository/archive?sha=<commit_sha>&path=<path>&exclude_paths=<path1,path2>"
```

## Compare branches, tags, or commits[](https://docs.gitlab.com/api/repositories/#compare-branches-tags-or-commits "Permalink")
History
  * `collapsed` and `too_large` response attributes [introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/199633) in GitLab 18.4.


Retrieves the differences between two branches, tags, or commits in a specified project. This endpoint can be accessed without authentication if the repository is publicly accessible.
When `compare_timeout` is `true`, the comparison exceeded size limits or timed out:
  * The `commits` array is always complete.
  * The `diffs` array might be incomplete.
  * Individual diff objects might have empty `diff` strings if their content exceeded limits.


```
GET /projects/:id/repository/compare
```

Supported attributes:
Attribute | Type | Required | Description
---|---|---|---
`from` | string | Yes | Commit SHA or branch name.
`id` | integer or string | Yes | ID or [URL-encoded path](https://docs.gitlab.com/api/rest/#namespaced-paths) of the project.
`to` | string | Yes | Commit SHA or branch name.
`from_project_id` | integer | No | ID to compare from.
`straight` | boolean | No | If `true`, comparison method is direct comparison between `from` and `to` (`from`..`to`). If `false`, compare using merge base (`from`…`to`). Default is `false`.
`unidiff` | boolean | No | If `true`, present diffs in the [unified diff](https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html) format. Default is `false`. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/130610) in GitLab 16.5.
If successful, returns [`200 OK`](https://docs.gitlab.com/api/rest/troubleshooting/#status-codes) and the following response attributes:
Attribute | Type | Description
---|---|---
`commit` | object | Details of the latest commit in the comparison.
`commits` | object array | Commits between the two references. Always complete, even when `compare_timeout` is `true`.
`commits[].author_email` | string | Commit author’s email address.
`commits[].author_name` | string | Commit author’s name.
`commits[].created_at` | datetime | Commit creation timestamp.
`commits[].id` | string | Full commit SHA.
`commits[].short_id` | string | Short commit SHA.
`commits[].title` | string | Commit title.
`compare_same_ref` | boolean | If `true`, comparison uses the same reference for both from and to.
`compare_timeout` | boolean | If `true`, the comparison exceeded size limits or timed out. The `diffs` array might be incomplete.
`diffs` | object array | List of file differences.
`diffs[].a_mode` | string | Old file mode.
`diffs[].b_mode` | string | New file mode.
`diffs[].collapsed` | boolean | If `true`, file diffs are excluded but can be fetched on request.
`diffs[].deleted_file` | boolean | If `true`, file has been removed.
`diffs[].diff` | string | Diff content showing changes made to the file.
`diffs[].new_file` | boolean | If `true`, file has been added.
`diffs[].new_path` | string | New path of the file.
`diffs[].old_path` | string | Old path of the file.
`diffs[].renamed_file` | boolean | If `true`, file has been renamed.
`diffs[].too_large` | boolean | If `true`, file diffs are excluded and cannot be retrieved.
`web_url` | string | Web URL for viewing the comparison.
Example request:
shell
```
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/5/repository/compare?from=main&to=feature"
```

Example response:
json
```
{
  "commit": {
    "id": "12d65c8dd2b2676fa3ac47d955accc085a37a9c1",
    "short_id": "12d65c8dd2b",
    "title": "JS fix",
    "author_name": "Example User",
    "author_email": "user@example.com",
    "created_at": "2014-02-27T10:27:00+02:00"
  },
  "commits": [{
    "id": "12d65c8dd2b2676fa3ac47d955accc085a37a9c1",
    "short_id": "12d65c8dd2b",
    "title": "JS fix",
    "author_name": "Example User",
    "author_email": "user@example.com",
    "created_at": "2014-02-27T10:27:00+02:00"
  }],
  "diffs": [{
    "old_path": "files/js/application.js",
    "new_path": "files/js/application.js",
    "a_mode": null,
    "b_mode": "100644",
    "diff": "@@ -24,8 +24,10 @@\n //= require g.raphael-min\n //= require g.bar-min\n //= require branch-graph\n-//= require highlightjs.min\n-//= require ace/ace\n //= require_tree .\n //= require d3\n //= require underscore\n+\n+function fix() { \n+  alert(\"Fixed\")\n+}",
    "collapsed": false,
    "too_large": false,
    "new_file": false,
    "renamed_file": false,
    "deleted_file": false
  }],
  "compare_timeout": false,
  "compare_same_ref": false,
  "web_url": "https://gitlab.example.com/janedoe/gitlab-foss/-/compare/ae73cb07c9eeaf35924a10f713b364d32b2dd34f...0b4bc9a49b562e85de7cc9e834518ea6828729b9"
}
```

## Get contributor list[](https://docs.gitlab.com/api/repositories/#get-contributor-list "Permalink")
History
  * `ref` [introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/156852) in GitLab 17.4.


Get repository contributors list. This endpoint can be accessed without authentication if the repository is publicly accessible.
The commit count returned does not include merge commits.
```
GET /projects/:id/repository/contributors
```

Supported attributes:
Attribute | Type | Required | Description
---|---|---|---
`id` | integer or string | Yes | ID or [URL-encoded path](https://docs.gitlab.com/api/rest/#namespaced-paths) of the project.
`order_by` | string | No | Order contributors by `name`, `email`, or `commits` (number of commits). If not specified, contributors are ordered by commit date.
`ref` | string | No | Name of a repository branch or tag. If not given, the default branch.
`sort` | string | No | Return contributors sorted in `asc` or `desc` order. Default is `asc`.
If successful, returns [`200 OK`](https://docs.gitlab.com/api/rest/troubleshooting/#status-codes) and the following response attributes:
Attribute | Type | Description
---|---|---
`additions` | integer | Number of line additions by the contributor.
`commits` | integer | Number of commits by the contributor.
`deletions` | integer | Number of line deletions by the contributor.
`email` | string | Email address of the contributor.
`name` | string | Name of the contributor.
Example request:
shell
```
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/7/repository/contributors"
```

Example response:
json
```
[{
  "name": "Example User",
  "email": "example@example.com",
  "commits": 117,
  "additions": 0,
  "deletions": 0
}, {
  "name": "Sample User",
  "email": "sample@example.com",
  "commits": 33,
  "additions": 0,
  "deletions": 0
}]
```

## Get merge base[](https://docs.gitlab.com/api/repositories/#get-merge-base "Permalink")
Get the common ancestor for 2 or more refs, such as commit SHAs, branch names, or tags.
```
GET /projects/:id/repository/merge_base
```

Supported attributes:
Attribute | Type | Required | Description
---|---|---|---
`id` | integer or string | Yes | ID or [URL-encoded path](https://docs.gitlab.com/api/rest/#namespaced-paths) of the project.
`refs` | array | Yes | Refs to find the common ancestor of. Accepts multiple refs.
If successful, returns [`200 OK`](https://docs.gitlab.com/api/rest/troubleshooting/#status-codes) and the following response attributes:
Attribute | Type | Description
---|---|---
`author_email` | string | Author’s email address.
`author_name` | string | Author’s name.
`authored_date` | datetime | Date when the commit was authored.
`committed_date` | datetime | Date when the commit was committed.
`committer_email` | string | Committer’s email address.
`committer_name` | string | Committer’s name.
`created_at` | datetime | Commit creation timestamp.
`extended_trailers` | object | Extended information about Git trailers.
`id` | string | Full commit SHA.
`message` | string | Full commit message.
`parent_ids` | array | List of parent commit SHAs.
`short_id` | string | Short commit SHA.
`title` | string | Commit title.
`trailers` | object | Git trailers parsed from the commit message.
`web_url` | string | URL to view the commit in the GitLab web interface.
Example request, with the refs truncated for readability:
shell
```
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/5/repository/merge_base?refs[]=304d257d&refs[]=0031876f"
```

Example response:
json
```
{
  "id": "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863",
  "short_id": "1a0b36b3",
  "title": "Initial commit",
  "created_at": "2014-02-27T08:03:18.000Z",
  "parent_ids": [],
  "message": "Initial commit\n",
  "author_name": "Example User",
  "author_email": "user@example.com",
  "authored_date": "2014-02-27T08:03:18.000Z",
  "committer_name": "Example User",
  "committer_email": "user@example.com",
  "committed_date": "2014-02-27T08:03:18.000Z",
  "trailers": {},
  "extended_trailers": {},
  "web_url": "https://gitlab.example.com/example-group/example-project/-/commit/1a0b36b3cdad1d2ee32457c102a8c0b7056fa863"
}
```

## Generate changelog data[](https://docs.gitlab.com/api/repositories/#generate-changelog-data "Permalink")
History
  * [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/172842) authentication through [CI/CD job token](https://docs.gitlab.com/ci/jobs/ci_job_token/) in GitLab 17.7.
  * `config_file_ref` attribute [introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/426108) in GitLab 18.2.


Generate changelog data based on commits in a repository, without committing them to a changelog file.
Works exactly like `POST /projects/:id/repository/changelog`, except the changelog data isn’t committed to any changelog file.
```
GET /projects/:id/repository/changelog
```

Supported attributes:
Attribute | Type | Required | Description
---|---|---|---
`version` | string | Yes | Version to generate the changelog for. Format must follow [semantic versioning](https://semver.org/).
`config_file` | string | No | Path of changelog configuration file in the project’s Git repository. Defaults to `.gitlab/changelog_config.yml`.
`config_file_ref` | string | No | Git reference (for example, branch) where the changelog configuration file is defined. Defaults to the default repository branch.
`date` | datetime | No | Date and time of the release. Uses ISO 8601 format. Example: `2016-03-11T03:45:40Z`. Defaults to the current time.
`from` | string | No | Start of the range of commits (as a SHA) to use for generating the changelog. This commit itself isn’t included in the list.
`to` | string | No | End of the range of commits (as a SHA) to use for the changelog. This commit is included in the list. Defaults to the HEAD of the default project branch.
`trailer` | string | No | Git trailer to use for including commits. Defaults to `Changelog`.
If successful, returns [`200 OK`](https://docs.gitlab.com/api/rest/troubleshooting/#status-codes) and the following response attributes:
Attribute | Type | Description
---|---|---
`notes` | string | Generated changelog data in Markdown format.
Example request:
shell
```
curl --header "PRIVATE-TOKEN: token" \
  --url "https://gitlab.com/api/v4/projects/42/repository/changelog?version=1.0.0"
```

Example response, with line breaks added for readability:
json
```
{
  "notes": "## 1.0.0 (2021-11-17)\n\n### feature (2 changes)\n\n-
    [Title 2](namespace13/project13@ad608eb642124f5b3944ac0ac772fecaf570a6bf)
    ([merge request](namespace13/project13!2))\n-
    [Title 1](namespace13/project13@3c6b80ff7034fa0d585314e1571cc780596ce3c8)
    ([merge request](namespace13/project13!1))\n"
}
```

## Add changelog data to file[](https://docs.gitlab.com/api/repositories/#add-changelog-data-to-file "Permalink")
History
  * [Generally available](https://gitlab.com/gitlab-org/gitlab/-/issues/364101) in GitLab 17.3. Feature flag `changelog_commits_limitation` removed.
  * `config_file_ref` [introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/426108) in GitLab 18.2.


Generate changelog data based on commits in a repository and commit them to a changelog file.
Given a [semantic version](https://semver.org/) and a range of commits, GitLab generates a changelog for all commits that use a particular [Git trailer](https://git-scm.com/docs/git-interpret-trailers). GitLab adds a new Markdown-formatted section to a changelog file in the Git repository of the project. The output format can be customized.
For performance and security reasons, parsing the changelog configuration is limited to 2 seconds. This limitation helps prevent potential DoS attacks from malformed changelog templates. If the request times out, consider reducing the size of your `changelog_config.yml` file.
For user-facing documentation, see [Changelogs](https://docs.gitlab.com/user/project/changelogs/).
```
POST /projects/:id/repository/changelog
```

Changelogs support the following attributes:
Attribute | Type | Required | Description
---|---|---|---
`version` 1 | string | Yes | Version to generate the changelog for. Format must follow [semantic versioning](https://semver.org/).
`branch` | string | No | Branch to commit the changelog changes to. Defaults to the project’s default branch.
`config_file` | string | No | Path to the changelog configuration file in the project’s Git repository. Defaults to `.gitlab/changelog_config.yml`.
`config_file_ref` | string | No | Git reference (for example, branch) where the changelog configuration file is defined. Defaults to the default repository branch.
`date` | datetime | No | Date and time of the release. Defaults to the current time.
`file` | string | No | File to commit the changes to. Defaults to `CHANGELOG.md`.
`from` 2 | string | No | SHA of the commit that marks the beginning of the range of commits to include in the changelog. This commit isn’t included in the changelog.
`message` | string | No | Commit message to use when committing the changes. Defaults to `Add changelog for version X`, where `X` is the value of the `version` argument.
`to` | string | No | SHA of the commit that marks the end of the range of commits to include in the changelog. This commit is included in the changelog. Defaults to the branch specified in the `branch` attribute. Limited to 15000 commits.
`trailer` | string | No | Git trailer to use for including commits. Defaults to `Changelog`. Case-sensitive: `Example` does not match `example` or `eXaMpLE`.
**Footnotes** :
  1. The `version` attribute can include or omit the `v` prefix. Both `1.0.0` and `v1.0.0` produce identical results. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/437616) in GitLab 17.0.
  2. When `from` is unspecified, GitLab automatically finds the last stable version tag that precedes your specified version. GitLab recognizes tags in `X.Y.Z` or `vX.Y.Z` format, following semantic versioning.
For example, if `version` is `2.1.0`, GitLab uses tag `v2.0.0`. When `version` is `1.1.1` or `1.2.0`, GitLab uses tag `v1.1.0`. Pre-release tags like `v1.0.0-pre1` are ignored.
If no suitable tag is found, the API returns an error and you must explicitly specify the `from` attribute.


### Examples[](https://docs.gitlab.com/api/repositories/#examples "Permalink")
These examples use [cURL](https://curl.se/) to perform HTTP requests. The example commands use these values:
  * Project ID: 42
  * Location: hosted on GitLab.com
  * Example API token: `token`


This command generates a changelog for version `1.0.0`.
The commit range:
  * Starts with the tag of the last release.
  * Ends with the last commit on the target branch. The default target branch is the project’s default branch.


If the last tag is `v0.9.0` and the default branch is `main`, the range of commits included in this example is `v0.9.0..main`:
shell
```
curl --request POST \
  --header "PRIVATE-TOKEN: token" \
  --data "version=1.0.0" \
  --url "https://gitlab.com/api/v4/projects/42/repository/changelog"
```

To generate the data on a different branch, specify the `branch` parameter. This command generates data from the `foo` branch:
shell
```
curl --request POST \
  --header "PRIVATE-TOKEN: token" \
  --data "version=1.0.0&branch=foo" \
  --url "https://gitlab.com/api/v4/projects/42/repository/changelog"
```

To use a different trailer, use the `trailer` parameter:
shell
```
curl --request POST --header "PRIVATE-TOKEN: token" \
  --data "version=1.0.0&trailer=Type" \
  --url "https://gitlab.com/api/v4/projects/42/repository/changelog"
```

To store the results in a different file, use the `file` parameter:
shell
```
curl --request POST \
  --header "PRIVATE-TOKEN: token" \
  --data "version=1.0.0&file=NEWS" \
  --url "https://gitlab.com/api/v4/projects/42/repository/changelog"
```

To specify a branch as a parameter, use the `to` attribute:
shell
```
curl --request GET \
  --header "PRIVATE-TOKEN: token" \
  --url "https://gitlab.com/api/v4/projects/42/repository/changelog?version=1.0.0&to=release/x.x.x"
```

## Migrate from manual changelog files[](https://docs.gitlab.com/api/repositories/#migrate-from-manual-changelog-files "Permalink")
When you migrate from an existing manually-managed changelog file to one that uses Git trailers, make sure that the changelog file matches [the expected format](https://docs.gitlab.com/user/project/changelogs/). Otherwise, new changelog entries added by the API might be inserted in an unexpected position. For example, if the version values in the manually-managed changelog file are specified as `vX.Y.Z` instead of `X.Y.Z`, then new changelog entries added using Git trailers are appended to the end of the changelog file.
[Issue 444183](https://gitlab.com/gitlab-org/gitlab/-/issues/444183) proposes customizing the version header format in changelog files. However, until that issue has been completed, the expected version header format in changelog files is `X.Y.Z`.
## Health[](https://docs.gitlab.com/api/repositories/#health "Permalink")
History
  * [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/182220) in GitLab 17.10. Guarded behind the [`project_repositories_health`](https://gitlab.com/gitlab-org/gitlab/-/issues/521115) feature flag.
  * New fields [added](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/191263) in GitLab 18.1.


Get statistics related to the health of a project repository.
This endpoint is rate-limited to 5 requests/hour per project when `generate` is `true`. The endpoint is only available to users with push access to the repository.
```
GET /projects/:id/repository/health
```

Supported attributes:
Attribute | Type | Required | Description
---|---|---|---
`generate` | boolean | No | If `true`, a new health report should be generated. Set this if the endpoint returns `404`.
If successful, returns [`200 OK`](https://docs.gitlab.com/api/rest/troubleshooting/#status-codes) and repository health statistics.
Example request:
shell
```
curl --header "PRIVATE-TOKEN: token" \
  --url "https://gitlab.com/api/v4/projects/42/repository/health"
```

Example response:
json
```
{
  "size": 2619748827,
  "references": {
    "loose_count": 13,
    "packed_size": 333978,
    "reference_backend": "REFERENCE_BACKEND_FILES"
  },
  "objects": {
    "size": 2180475409,
    "recent_size": 2180453999,
    "stale_size": 21410,
    "keep_size": 0,
    "packfile_count": 1,
    "reverse_index_count": 1,
    "cruft_count": 0,
    "keep_count": 0,
    "loose_objects_count": 36,
    "stale_loose_objects_count": 36,
    "loose_objects_garbage_count": 0
  },
  "commit_graph": {
    "commit_graph_chain_length": 1,
    "has_bloom_filters": true,
    "has_generation_data": true,
    "has_generation_data_overflow": false
  },
  "bitmap": null,
  "multi_pack_index": {
    "packfile_count": 1,
    "version": 1
  },
  "multi_pack_index_bitmap": {
    "has_hash_cache": true,
    "has_lookup_table": true,
    "version": 1
  },
  "alternates": null,
  "is_object_pool": false,
  "last_full_repack": {
    "seconds": 1745892013,
    "nanos": 0
  },
  "updated_at": "2025-05-14T02:31:08.022Z"
}
```

For a description of each field in the response, see the [`RepositoryInfoResponse`](https://gitlab.com/gitlab-org/gitaly/blob/fcb986a6482f82b088488db3ed7ca35adfa42fdc/proto/repository.proto#L444) protobuf message.
## Related topics[](https://docs.gitlab.com/api/repositories/#related-topics "Permalink")
  * User documentation for [changelogs](https://docs.gitlab.com/user/project/changelogs/)


Was this page helpful?YesNo
Edit this page
  *     * [ Open in Web IDE`.`Quickly and easily edit multiple files. ](https://gitlab.com/-/ide/project/gitlab-org/gitlab/edit/master/-/doc/api/repositories.md)
    * [ View page sourceEdit this file only. ](https://gitlab.com/gitlab-org/gitlab/-/blob/master/doc/api/repositories.md)
    * [ Create an issueSuggest improvements. ](https://gitlab.com/gitlab-org/gitlab/-/issues/new?issuable_template=Documentation)


  * [List all repository trees in a project](https://docs.gitlab.com/api/repositories/#list-all-repository-trees-in-a-project)
  * [Retrieve a blob from a repository](https://docs.gitlab.com/api/repositories/#retrieve-a-blob-from-a-repository)
  * [Retrieve raw blob content](https://docs.gitlab.com/api/repositories/#retrieve-raw-blob-content)
  * [Retrieve file archive from a repository](https://docs.gitlab.com/api/repositories/#retrieve-file-archive-from-a-repository)
  * [Compare branches, tags, or commits](https://docs.gitlab.com/api/repositories/#compare-branches-tags-or-commits)
  * [Get contributor list](https://docs.gitlab.com/api/repositories/#get-contributor-list)
  * [Get merge base](https://docs.gitlab.com/api/repositories/#get-merge-base)
  * [Generate changelog data](https://docs.gitlab.com/api/repositories/#generate-changelog-data)
  * [Add changelog data to file](https://docs.gitlab.com/api/repositories/#add-changelog-data-to-file)
  * [Examples](https://docs.gitlab.com/api/repositories/#examples)
  * [Migrate from manual changelog files](https://docs.gitlab.com/api/repositories/#migrate-from-manual-changelog-files)
  * [Health](https://docs.gitlab.com/api/repositories/#health)
  * [Related topics](https://docs.gitlab.com/api/repositories/#related-topics)


[![GitLab Docs logo](https://docs.gitlab.com/gitlab-logo-footer.svg)](https://docs.gitlab.com/)
  * [Facebook](https://www.facebook.com/gitlab)
  * [LinkedIn](https://www.linkedin.com/company/gitlab-com)
  * [Twitter](https://twitter.com/gitlab)
  * [YouTube](https://www.youtube.com/channel/UCnMGQ8QHMAnVIsI3xJrihhg)

[![Creative Commons License](https://docs.gitlab.com/by-sa.svg)](https://creativecommons.org/licenses/by-sa/4.0/)
Company
  * [About GitLab](https://about.gitlab.com/company/)
  * [View pricing](https://about.gitlab.com/pricing/)
  * [Try GitLab for free](https://about.gitlab.com/free-trial/)


Feedback
  * [View page source](https://gitlab.com/gitlab-org/gitlab/-/blob/master/doc/api/repositories.md)
  * [Edit in Web IDE](https://gitlab.com/-/ide/project/gitlab-org/gitlab/edit/master/-/doc/api/repositories.md)
  * [Contribute to GitLab](https://about.gitlab.com/community/contribute/)
  * [Suggest updates](https://gitlab.com/gitlab-org/gitlab/-/issues/new?issuable_template=Documentation)


Help & Community
  * [Get certified](https://university.gitlab.com/pages/certifications)
  * [Get support](https://about.gitlab.com/support/)
  * [Post on the GitLab forum](https://forum.gitlab.com/new-topic?title=topic%20title&body=topic%20body&tags=docs-feedback)


Resources
  * [Terms](https://about.gitlab.com/terms/)
  * [Privacy statement](https://about.gitlab.com/privacy/)
  * [Use of generative AI](https://docs.gitlab.com/legal/use_generative_ai/)
  * [Acceptable use of user licenses](https://docs.gitlab.com/legal/licensing_policy/)
  * Cookie Preferences


![](https://cdn.bizible.com/ipv?_biz_r=&_biz_h=800054037&_biz_u=10503924d6784ad3f2d352558587a67a&_biz_l=https%3A%2F%2Fdocs.gitlab.com%2Fapi%2Frepository_files%2F&_biz_t=1772174440983&_biz_i=Repository%20files%20API%20%7C%20GitLab%20Docs&_biz_n=145&rnd=636836&cdn_o=a&_biz_z=1772174441098)![](https://cdn.bizible.com/ipv?_biz_r=&_biz_h=800054037&_biz_u=10503924d6784ad3f2d352558587a67a&_biz_l=https%3A%2F%2Fdocs.gitlab.com%2Fapi%2Frepositories%2F&_biz_t=1772174441097&_biz_i=Repositories%20API%20%7C%20GitLab%20Docs&_biz_n=146&rnd=180553&cdn_o=a&_biz_z=1772174441099)
![Company Logo](https://cdn.cookielaw.org/logos/aa14a5c8-79e3-442a-8177-464ad850b19d/e46c1d0d-1f66-481f-bc06-5427671431da/253e6fee-c4c0-4b60-bc35-79cdae5dda32/gitlab-logo-100.png)
## Privacy Preference Center
## Privacy Preference Center
  * ### Your Privacy
  * ### Strictly Necessary Cookies
  * ### Functionality Cookies
  * ### Performance and Analytics Cookies
  * ### Targeting and Advertising Cookies
  * ### Ad User Data
  * ### Ad Personalization


#### Your Privacy
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
[Cookie Policy](https://about.gitlab.com/privacy/cookies/)
**User ID:** 42fad8d5-ed56-4786-8d74-3c72635252d2
_This User ID will be used as a unique identifier while storing and accessing your preferences for future._
**Timestamp:** --
#### Strictly Necessary Cookies
Always Active
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, enabling you to securely log into the site, filling in forms, or using the customer checkout. GitLab processes any personal data collected through these cookies on the basis of our legitimate interest.
Cookies Details
#### Functionality Cookies
Functionality Cookies
These cookies enable helpful but non-essential website functions that improve your website experience. By recognizing you when you return to our website, they may, for example, allow us to personalize our content for you or remember your preferences. If you do not allow these cookies then some or all of these services may not function properly. GitLab processes any personal data collected through these cookies on the basis of your consent
Cookies Details
#### Performance and Analytics Cookies
Performance and Analytics Cookies
These cookies allow us and our third-party service providers to recognize and count the number of visitors on our websites and to see how visitors move around our websites when they are using it. This helps us improve our products and ensures that users can easily find what they need on our websites. These cookies usually generate aggregate statistics that are not associated with an individual. To the extent any personal data is collected through these cookies, GitLab processes that data on the basis of your consent.
Cookies Details
#### Targeting and Advertising Cookies
Targeting and Advertising Cookies
These cookies enable different advertising related functions. They may allow us to record information about your visit to our websites, such as pages visited, links followed, and videos viewed so we can make our websites and the advertising displayed on it more relevant to your interests. They may be set through our website by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant advertisements on other websites. GitLab processes any personal data collected through these cookies on the basis of your consent.
Cookies Details
#### Ad User Data
Ad User Data
Sets consent for sending user data to Google for advertising purposes.
Cookies Details
#### Ad Personalization
Ad Personalization
Sets consent for personalized advertising.
Cookies Details
Back Button
### Cookie List
Filter Button
Consent Leg.Interest
checkbox label label
checkbox label label
checkbox label label
Clear
  * checkbox label label


Apply Cancel
Confirm My Choices
Allow All
[![Powered by Onetrust](https://cdn.cookielaw.org/logos/static/powered_by_logo.svg)](https://www.onetrust.com/products/cookie-consent/)
