Use this API to manage Git repositories.
Retrieve file archive from a repository
GET /api/v4/projects/{id}/repository/archive
Retrieves the file archive of a 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.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- Example: 1 |
shaQuery | String | Commit SHA to download. Example: 7d70e02340bac451f281 |
ref_Query | String | Type of ref in sha.Allowed values: heads,tags |
formatQuery | String | Archive format,archive..bz2,gz,tar,tar.,tar.,tb2,tbz,tbz2,tgz,zip.tar.Example: tar. |
pathQuery | String | Subpath of the repository to download. Example: files/ |
include_Query | Boolean | If true,false,Default: true |
exclude_Query | Array of strings | Comma- Default: [] |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | — |
400 | Bad Request | — |
404 | Not Found | — |
Get contents of multiple files in a single request
POST /api/v4/projects/{id}/repository/blobs/batch
Blob content is Base64 encoded. Each blob is truncated to the first 1 MB; the truncated field indicates when this happens. size is the full blob size in bytes. Files that do not exist at the requested reference are omitted from the response. This endpoint requires authentication. It is rate limited per user and project, to 5 requests per minute by default, set by the project_repositories_blobs_batch_limit application setting. This endpoint is behind the repository_blobs_batch_api feature flag, disabled by default. This feature was introduced in GitLab 19.3.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- Example: 1 |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
filesRequired | Array of objects | Array of file objects to retrieve, |
files[].Required | String | Path of the file in the repository Example: app/ |
files[]. | String | Branch, Example: main |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | Array of APIEntities |
400 | Bad Request | — |
401 | Unauthorized | — |
403 | Forbidden | — |
404 | Not Found | — |
Retrieve a blob from a repository
GET /api/v4/projects/{id}/repository/blobs/{sha}
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. For text files not stored as valid UTF-8 in Git, content is converted to UTF-8 before Base64 encoding, and size is the raw blob size, which might differ from the length of the decoded content.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- Example: 1 |
shaPath, | String | SHA of the blob Example: 7d70e02340bac451f281 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | — |
400 | Bad Request | — |
404 | Not Found | — |
Retrieve raw blob content
GET /api/v4/projects/{id}/repository/blobs/{sha}/raw
Retrieves the raw file contents for a blob, by blob SHA. This endpoint can be accessed without authentication if the repository is publicly accessible.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- Example: 1 |
shaPath, | String | SHA of the blob Example: 7d70e02340bac451f281 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | — |
400 | Bad Request | — |
404 | Not Found | — |
List files changed between two commits
GET /api/v4/projects/{id}/repository/changed_paths
Returns the path, change status, and file modes for every path that differs between two refs. This endpoint requires authentication. This endpoint is behind the repository_changed_paths_api feature flag, disabled by default. This feature was introduced in GitLab 19.4.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- Example: 1 |
fromQuery, | String | The commit SHA or branch/ Maximum length: 255Example: main |
toQuery, | String | The commit SHA or branch/ Maximum length: 255Example: feature |
find_Query | Boolean | If true, Default: false |
pageQuery | Integer | Page number of results to retrieve Default: 1Example: 1 |
per_Query | Integer | Number of items to list per page Default: 20Example: 20 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | Array of APIEntities |
400 | Bad Request | — |
401 | Unauthorized | — |
403 | Forbidden | — |
404 | Not Found | — |
429 | Too Many Requests | — |
Generate changelog data
GET /api/v4/projects/{id}/repository/changelog
Generates 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 is not committed to any changelog file. Add a .txt suffix to the path, as in GET /projects/:id/repository/changelog.txt, to return the changelog as plain text Markdown instead of JSON.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- Example: 1 |
versionQuery, | String | Version to generate the changelog for.v prefix:1. and v1. give the same resultPattern: (?:Example: 1. |
fromQuery | String | First commit in the range of commits,version is used.X. or v format are recognized,v1. are ignored.fromExample: ed899a2f4b50b4370fee |
toQuery | String | Last commit in the range of commits,branch instead.Example: 6104942438c14ec7bd21 |
dateQuery | String (date- | Date and time of the release. Example: 2021- |
trailerQuery | String | Git trailer to use for including commits.Example does not match example or eDefault: ChangelogExample: Changelog |
config_Query | String | Path to the changelog configuration file in the project’s Git repository..Example: . |
config_Query | String | Git reference, Example: main |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not Found | — |
Add changelog data to file
POST /api/v4/projects/{id}/repository/changelog
Generates changelog data based on commits in a repository and commits it to a changelog file. Given a semantic version and a range of commits, GitLab generates a changelog for all commits that use a specific Git trailer, and adds a new Markdown section to the changelog file. The output format can be customized. Parsing the changelog configuration is limited to 2 seconds. If the request times out, reduce the size of the changelog configuration file.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- Example: 1 |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
branch | String | Name of the branch to commit the changelog changes to. Example: main |
config_ | String | Path to the changelog configuration file in the project’s Git repository..Example: . |
config_ | String | Git reference, Example: main |
date | String (date- | Date and time of the release. Example: 2021- |
file | String | File to commit the changes to Default: CHANGELOG.Example: CHANGELOG. |
from | String | First commit in the range of commits,version is used.X. or v format are recognized,v1. are ignored.fromExample: ed899a2f4b50b4370fee |
message | String | Commit message to use when committing the changelog changes.Add changelog for version X,X is the value of the version parameterExample: Initial commit |
to | String | Last commit in the range of commits,branch instead.Example: 6104942438c14ec7bd21 |
trailer | String | Git trailer to use for including commits.Example does not match example or eDefault: ChangelogExample: Changelog |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | — |
400 | Bad Request | — |
404 | Not Found | — |
Compare branches, tags, or commits
GET /api/v4/projects/{id}/repository/compare
Compares branches, tags, or commits. 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: the commits array is still complete, but the diffs array might be incomplete, and individual diff objects might have empty diff strings.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- Example: 1 |
fromQuery, | String | Ref to compare from. Example: main |
toQuery, | String | Ref to compare to. Example: feature |
from_Query | Integer | ID of the project to compare from Example: 1 |
straightQuery | Boolean | If true,from and to (from.to).false,from…to)Default: false |
unidiffQuery | Boolean | If true,Default: false |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
403 | Forbidden | — |
404 | Not Found | — |
503 | Service Unavailable | — |
Retrieve contributors metrics
GET /api/v4/projects/{id}/repository/contributors
Retrieves a list of contributors to a specified repository. This endpoint can be accessed without authentication if the repository is publicly accessible. The commit count does not include merge commits.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- Example: 1 |
pageQuery | Integer | Page number of results to retrieve Default: 1Example: 1 |
per_Query | Integer | Number of items to list per page Default: 20Example: 20 |
refQuery | String | Name of a repository branch or tag. Example: main |
order_Query | String | Sort results by the specified field Allowed values: email,name,commitsDefault: commits |
sortQuery | String | Sort results in ascending or descending order Allowed values: asc,descDefault: asc |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not Found | — |
Get diff statistics between two commits
GET /api/v4/projects/{id}/repository/diff_stats
Returns the number of added and deleted lines for every file that differs between two refs. This endpoint requires authentication. This endpoint is behind the repository_diff_stats_api feature flag, disabled by default. This feature was introduced in GitLab 19.4.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- Example: 1 |
fromQuery, | String | The commit SHA or branch/ Maximum length: 255Example: main |
toQuery, | String | The commit SHA or branch/ Maximum length: 255Example: feature |
pageQuery | Integer | Page number of results to retrieve Default: 1Example: 1 |
per_Query | Integer | Number of items to list per page Default: 20Example: 20 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | Array of APIEntities |
400 | Bad request | — |
401 | Unauthorized | — |
403 | Forbidden | — |
404 | Not found | — |
429 | Too many requests | — |
Retrieve diverging commit counts between two refs
GET /api/v4/projects/{id}/repository/diverging_commits
Retrieves the number of commits by which the to ref is ahead of and behind the from ref. behind is the number of commits in from that are not in to, and ahead is the number of commits in to that are not in from. This endpoint requires authentication. This endpoint is behind the repository_diverging_commits_api feature flag, disabled by default. This feature was introduced in GitLab 19.3.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- Example: 1 |
fromQuery, | String | Ref to compare from. Maximum length: 255Example: main |
toQuery, | String | Ref to compare to. Maximum length: 255Example: feature |
max_Query | Integer | Maximum number of commits to count.0 for unlimitedDefault: 0Minimum: 0Example: 1000 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad request | — |
401 | Unauthorized | — |
403 | Forbidden | — |
404 | Not found | — |
429 | Too many requests | — |
Retrieve repository health statistics
GET /api/v4/projects/{id}/repository/health
Retrieves statistics related to the health of a project repository. This endpoint is rate-limited to 5 requests/hour per project when generate is true. Available only to users with push access to the repository. This feature was introduced in GitLab 17.10.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- Example: 1 |
generateQuery | Boolean | If true,404Default: false |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not Found | — |
Retrieve a merge base
GET /api/v4/projects/{id}/repository/merge_base
Retrieves the merge base, the common ancestor, of two or more refs, such as commit SHAs, branch names, or tags.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- Example: 1 |
refsQuery, | Array of strings | Refs to find the common ancestor of. Example: ["main", |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not Found | — |
List all repository trees in a project
GET /api/v4/projects/{id}/repository/tree
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. Use with_last_commit to include the last commit that changed each entry. with_last_commit cannot be combined with recursive.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- Example: 1 |
refQuery | String | Name of a repository branch or tag. Maximum length: 1024Example: main |
pathQuery | String | Path inside the repository, Maximum length: 1024Example: files/ |
recursiveQuery | Boolean | If true,Default: false |
with_Query | Boolean | If true,recursive.Default: false |
pageQuery | Integer | Page number of results to retrieve Default: 1Example: 1 |
per_Query | Integer | Number of items to list per page Default: 20Example: 20 |
paginationQuery | String | Pagination method.keyset uses the keyset-none is valid only if recursive is trueAllowed values: legacy,keyset,noneDefault: legacy |
page_Query | String | Tree record ID at which to fetch the next page. Example: a1e8f8d745cc87e3a924 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | 404 Project Not Found | — |
Schemas
Objects returned by the operations above and objects nested in their request bodies.
APIEntitiesBatchBlob
| Property | Type | Description |
|---|---|---|
content | String | Base64- Example: VGhpcy |
encoding | String | Encoding of content.base64Example: base64 |
path | String | Path of the file in the repository Example: app/ |
ref | String | Branch, Example: main |
size | Integer | Full size of the blob in bytes Example: 1476 |
truncated | Boolean | Whether content is truncated to the first 1 MB of the blobExample: false |
APIEntitiesChangedPath
| Property | Type | Description |
|---|---|---|
new_ | String | New file mode Example: 100644 |
old_ | String | Previous file mode Example: 100644 |
old_ | String | Previous path of the file.path unless the file was renamed or copiedExample: app/ |
path | String | Path of the file Example: app/ |
status | String | Change type.ADDED,MODIFIED,DELETED,RENAMED,TYPE_,COPIEDExample: MODIFIED |
APIEntitiesChangelog
| Property | Type | Description |
|---|---|---|
notes | String | Generated changelog data in Markdown format Example: ## 1. |
APIEntitiesCommit
| Property | Type | Description |
|---|---|---|
author_ | String | Email address of the commit author Example: john@example. |
author_ | String | Name of the commit author Example: John Smith |
authored_ | String (date- | Date and time when the commit was authored Example: 2012- |
committed_ | String (date- | Date and time when the commit was committed Example: 2012- |
committer_ | String | Email address of the committer Example: jack@example. |
committer_ | String | Name of the committer Example: Jack Smith |
created_ | String (date- | Date and time when the commit was created.committed_Example: 2017- |
extended_ | Object | Git trailers parsed from the commit message, Example: {"Signed- |
id | String | Full SHA of the commit Example: 2695effb5807a22ff3d1 |
message | String | Full commit message Example: Initial commit |
parent_ | Array of strings | SHAs of the parent commits Example: ["2a4b78934375d7f53875 |
short_ | String | Short SHA of the commit Example: 2695effb |
title | String | Title of the commit message Example: Initial commit |
trailers | Object | Git trailers parsed from the commit message. Example: {"Merged- |
web_ | String | URL to view the commit in the Git Example: https: |
APIEntitiesCompare
| Property | Type | Description |
|---|---|---|
commit | APIEntities | Latest commit in the comparison |
commits | Array of APIEntities | Commits between the two references.compare_ is true.compare_, |
compare_ | Boolean | If true,from and to resolve to the same commit |
compare_ | Boolean | If true,diffs might be incomplete |
diffs | Array of APIEntities | File differences between the two references |
web_ | String | URL to view the comparison in the Git Example: https: |
APIEntitiesContributor
| Property | Type | Description |
|---|---|---|
additions | Integer | Number of lines added by the contributor Example: 3 |
commits | Integer | Number of commits by the contributor Example: 117 |
deletions | Integer | Number of lines deleted by the contributor Example: 5 |
email | String | Email address of the contributor Example: johndoe@example. |
name | String | Name of the contributor Example: John Doe |
APIEntitiesDiff
| Property | Type | Description |
|---|---|---|
a_ | String | Old file mode of the file Example: 100755 |
b_ | String | New file mode of the file Example: 100644 |
collapsed | Boolean | If true, |
deleted_ | Boolean | If true, |
diff | String | Diff of the changes made to the file Example: @@ - |
generated_ | Boolean | If true, |
new_ | Boolean | If true, |
new_ | String | New path of the file Example: doc/ |
old_ | String | Old path of the file Example: doc/ |
renamed_ | Boolean | If true, |
too_ | Boolean | If true, |
APIEntitiesDiffStat
| Property | Type | Description |
|---|---|---|
additions | Integer | Number of added lines Example: 10 |
deletions | Integer | Number of deleted lines Example: 3 |
old_ | String | Previous path of the file.path when the file was renamedExample: app/ |
path | String | Path of the file Example: app/ |
APIEntitiesDivergingCommitCount
| Property | Type | Description |
|---|---|---|
ahead | Integer | Number of commits in to that are not in fromExample: 5 |
behind | Integer | Number of commits in from that are not in toExample: 3 |
APIEntitiesRepositoryHealth
| Property | Type | Description |
|---|---|---|
alternates | Object | — |
bitmap | APIEntities | — |
commit_ | APIEntities | — |
is_ | Boolean | — |
last_ | APIEntities | — |
multi_ | APIEntities | — |
multi_ | APIEntities | — |
objects | APIEntities | — |
references | APIEntities | — |
size | Integer | — |
updated_ | String (date- | Example:2025- |
APIEntitiesRepositoryHealthBitmap
| Property | Type | Description |
|---|---|---|
has_ | Boolean | — |
has_ | Boolean | — |
version | Integer | — |
APIEntitiesRepositoryHealthCommitGraph
| Property | Type | Description |
|---|---|---|
commit_ | Integer | — |
has_ | Boolean | — |
has_ | Boolean | — |
has_ | Boolean | — |
APIEntitiesRepositoryHealthLastFullRepack
| Property | Type | Description |
|---|---|---|
nanos | Integer | — |
seconds | Integer | — |
APIEntitiesRepositoryHealthMultiPackIndex
| Property | Type | Description |
|---|---|---|
packfile_ | Integer | — |
version | Integer | — |
APIEntitiesRepositoryHealthObjects
| Property | Type | Description |
|---|---|---|
cruft_ | Integer | — |
keep_ | Integer | — |
keep_ | Integer | — |
loose_ | Integer | — |
loose_ | Integer | — |
packfile_ | Integer | — |
recent_ | Integer | — |
reverse_ | Integer | — |
size | Integer | — |
stale_ | Integer | — |
stale_ | Integer | — |
APIEntitiesRepositoryHealthReferences
| Property | Type | Description |
|---|---|---|
loose_ | Integer | — |
packed_ | Integer | — |
reference_ | String | — |
APIEntitiesTreeObject
| Property | Type | Description |
|---|---|---|
id | String | Example:a1e8f8d745cc87e3a924 |
last_ | APIEntities | — |
mode | String | Example:040000 |
name | String | Example:html |
path | String | Example:files/ |
type | String | Example:tree |