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 | The ID or URL- Example: 1 |
shaQuery | String | The commit sha of the archive to be downloaded Example: 7d70e02340bac451f281 |
ref_Query | String | Type of ref in sha, Allowed values: heads,tags |
formatQuery | String | The archive format Example: tar. |
pathQuery | String | Subfolder of the repository to be downloaded Example: files/ |
include_Query | Boolean | Used to exclude LFS objects from archive 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
Each blob is truncated to the first 1 MB; the truncated field indicates when this happens.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- Example: 1 |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
filesRequired | Array of objects | Array of file objects to retrieve (max 20) |
files[].Required | String | The file path Example: app/ |
files[]. | String | The branch, Example: main |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | 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.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- Example: 1 |
shaPath, | String | The commit hash 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 | The ID or URL- Example: 1 |
shaPath, | String | The commit hash 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.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The 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 | Current page number Default: 1Example: 1 |
per_Query | Integer | Number of items per page Default: 20Example: 20 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | 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.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- Example: 1 |
versionQuery, | String | The version of the release, Pattern: (?:Example: 1. |
fromQuery | String | The first commit in the range of commits to use for the changelog Example: ed899a2f4b50b4370fee |
toQuery | String | The last commit in the range of commits to use for the changelog Example: 6104942438c14ec7bd21 |
dateQuery | String (date- | The date and time of the release Example: 2021- |
trailerQuery | String | The Git trailer to use for determining if commits are to be included in the changelog Default: ChangelogExample: Changelog |
config_Query | String | The file path to the configuration file as stored in the project’s Git repository. Example: . |
config_Query | String | The git reference (for example, 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
Adds changelog data to file.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- Example: 1 |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
branch | String | The branch to commit the changelog changes to Example: main |
config_ | String | The file path to the configuration file as stored in the project’s Git repository. Example: . |
config_ | String | The git reference (for example, Example: main |
date | String (date- | The date and time of the release Example: 2021- |
file | String | The file to commit the changelog changes to Default: CHANGELOG.Example: CHANGELOG. |
from | String | The first commit in the range of commits to use for the changelog Example: ed899a2f4b50b4370fee |
message | String | The commit message to use when committing the changelog Example: Initial commit |
to | String | The last commit in the range of commits to use for the changelog Example: 6104942438c14ec7bd21 |
trailer | String | The Git trailer to use for determining if commits are to be included in the changelog Default: 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.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- Example: 1 |
fromQuery, | String | The commit, Example: main |
toQuery, | String | The commit, Example: feature |
from_Query | Integer | The project to compare from Example: 1 |
straightQuery | Boolean | Comparison method,true for direct comparison between from and to (from.to),false to compare using merge base (from…to)Default: false |
unidiffQuery | Boolean | A diff in a Unified diff format Default: false |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not Found | — |
Retrieve contributors metrics
GET /api/v4/projects/{id}/repository/contributors
Retrieves a list of contributors to a specified repository.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- Example: 1 |
pageQuery | Integer | Current page number Default: 1Example: 1 |
per_Query | Integer | Number of items per page Default: 20Example: 20 |
refQuery | String | The name of a repository branch or tag, Example: main |
order_Query | String | Return contributors ordered by name or email or commitsAllowed values: email,name,commitsDefault: commits |
sortQuery | String | Sort by asc (ascending) or desc (descending) 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.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The 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 | Current page number Default: 1Example: 1 |
per_Query | Integer | Number of items per page Default: 20Example: 20 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | 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
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- Example: 1 |
fromQuery, | String | The ref to compare from Maximum length: 255Example: main |
toQuery, | String | The ref to compare to Maximum length: 255Example: feature |
max_Query | Integer | Maximum number of commits to count. Default: 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.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- Example: 1 |
generateQuery | Boolean | Triggers a new health report to be generated Default: 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 for two specified commits.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- Example: 1 |
refsQuery, | Array of strings | The 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 | The ID or URL- Example: 1 |
refQuery | String | The name of a repository branch or tag, Maximum length: 1024Example: main |
pathQuery | String | The path of the tree Maximum length: 1024Example: files/ |
recursiveQuery | Boolean | Used to get a recursive tree Default: false |
with_Query | Boolean | Include the last commit for each tree entry. Default: false |
pageQuery | Integer | Current page number Default: 1Example: 1 |
per_Query | Integer | Number of items per page Default: 20Example: 20 |
paginationQuery | String | Specify the pagination method (“none” is only valid if “recursive” is true) Allowed values: legacy,keyset,noneDefault: legacy |
page_Query | String | Record from which to start the keyset pagination 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 | Example:VGhpcy |
encoding | String | Example:base64 |
path | String | Example:app/ |
ref | String | Example:main |
size | Integer | Example:1476 |
truncated | Boolean | Example:false |
APIEntitiesChangedPath
| Property | Type | Description |
|---|---|---|
new_ | String | Example:100644 |
old_ | String | Example:100644 |
old_ | String | Example:app/ |
path | String | Example:app/ |
status | String | Example:MODIFIED |
APIEntitiesChangelog
| Property | Type | Description |
|---|---|---|
notes | String | Example:## 1. |
APIEntitiesCommit
| Property | Type | Description |
|---|---|---|
author_ | String | Example:john@example. |
author_ | String | Example:John Smith |
authored_ | String (date- | Example:2012- |
committed_ | String (date- | Example:2012- |
committer_ | String | Example:jack@example. |
committer_ | String | Example:Jack Smith |
created_ | String (date- | Example:2017- |
extended_ | Object | Example:{"Signed- |
id | String | Example:2695effb5807a22ff3d1 |
message | String | Example:Initial commit |
parent_ | Array of strings | Example:["2a4b78934375d7f53875 |
short_ | String | Example:2695effb |
title | String | Example:Initial commit |
trailers | Object | Example:{"Merged- |
web_ | String | Example:https: |
APIEntitiesCompare
| Property | Type | Description |
|---|---|---|
commit | APIEntities | — |
commits | Array of APIEntities | — |
compare_ | Boolean | — |
compare_ | Boolean | — |
diffs | Array of APIEntities | — |
web_ | String | Example:https: |
APIEntitiesContributor
| Property | Type | Description |
|---|---|---|
additions | Integer | Example:3 |
commits | Integer | Example:117 |
deletions | Integer | Example:5 |
email | String | Example:johndoe@example. |
name | String | Example:John Doe |
APIEntitiesDiff
| Property | Type | Description |
|---|---|---|
a_ | String | Example:100755 |
b_ | String | Example:100644 |
collapsed | Boolean | — |
deleted_ | Boolean | — |
diff | String | Example:@@ - |
generated_ | Boolean | — |
new_ | Boolean | — |
new_ | String | Example:doc/ |
old_ | String | Example:doc/ |
renamed_ | Boolean | — |
too_ | Boolean | — |
APIEntitiesDiffStat
| Property | Type | Description |
|---|---|---|
additions | Integer | Example:10 |
deletions | Integer | Example:3 |
old_ | String | Example:app/ |
path | String | Example:app/ |
APIEntitiesDivergingCommitCount
| Property | Type | Description |
|---|---|---|
ahead | Integer | Example:5 |
behind | Integer | Example: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 |