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

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
Example: 1
sha
Query
StringCommit SHA to download. Accepts a tag, branch reference, or SHA. If omitted, defaults to the tip of the default branch
Example: 7d70e02340bac451f281cecf0a980907974bd8be
ref_type
Query
StringType of ref in sha. Use to select the correct ref when a branch and tag share a name
Allowed values: heads, tags
format
Query
StringArchive format
Example: tar.gz
path
Query
StringSubpath of the repository to download. An empty string returns the whole repository
Example: files/archives
include_lfs_blobs
Query
BooleanIf true, LFS objects are included in the archive. When set to false, LFS objects are excluded
Default: true
exclude_paths
Query
Array of stringsComma-separated list of paths to exclude from the archive
Default: []

Responses

CodeDescriptionSchema
200OK—
400Bad Request—
404Not 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

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
Example: 1

Request body (application/json)

PropertyTypeDescription
files
Required
Array of objectsArray of file objects to retrieve, up to a maximum of 20
files[].path
Required
StringPath of the file in the repository
Example: app/models/user.rb
files[].refStringBranch, tag, or commit to read the file from. Defaults to the default branch
Example: main

Responses

CodeDescriptionSchema
200OKArray of APIEntitiesBatchBlob
400Bad Request—
401Unauthorized—
403Forbidden—
404Not 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

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
Example: 1
sha
Path, required
StringSHA of the blob
Example: 7d70e02340bac451f281cecf0a980907974bd8be

Responses

CodeDescriptionSchema
200OK—
400Bad Request—
404Not 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

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
Example: 1
sha
Path, required
StringSHA of the blob
Example: 7d70e02340bac451f281cecf0a980907974bd8be

Responses

CodeDescriptionSchema
200OK—
400Bad Request—
404Not 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

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
Example: 1
from
Query, required
StringThe commit SHA or branch/tag to compare from
Maximum length: 255
Example: main
to
Query, required
StringThe commit SHA or branch/tag to compare to
Maximum length: 255
Example: feature
find_renames
Query
BooleanIf true, detect file renames
Default: false
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20

Responses

CodeDescriptionSchema
200OKArray of APIEntitiesChangedPath
400Bad Request—
401Unauthorized—
403Forbidden—
404Not Found—
429Too 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

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
Example: 1
version
Query, required
StringVersion to generate the changelog for. Must follow semantic versioning format
Pattern: (?:(?:(0|[1-9]\d*))\.(?:(0|[1-9]\d*))\.(?:(0|[1-9]\d*)))(?:(?:-((?:\d*[a-zA-Z\-][0-9a-zA-Z\-]*|[1-9]\d*|0)(?:\.(?:\d*[a-zA-Z\-][0-9a-zA-Z\-]*|[1-9]\d*|0))*))?(?:\+([0-9a-zA-Z\-]+(?:\.[0-9a-zA-Z\-]+)*))?)
Example: 1.0.0
from
Query
StringFirst commit in the range of commits, as a SHA, to use for the changelog. This commit is not included in the changelog. If omitted, the most recent stable version tag before version is used
Example: ed899a2f4b50b4370feeea94676502b42383c746
to
Query
StringLast commit in the range of commits, as a SHA, to use for the changelog. This commit is included in the changelog. If omitted, uses the latest commit on the default branch. For the Add changelog data to file operation, uses the latest commit on branch instead. The range can contain at most 15,000 commits
Example: 6104942438c14ec7bd21c6cd5bd995272b3faff6
date
Query
String (date-time)Date and time of the release. Defaults to the current time
Example: 2021-09-20T11:50:22.001+00:00
trailer
Query
StringGit trailer to use for including commits. Case-sensitive: Example does not match example or eXaMpLE
Default: Changelog
Example: Changelog
config_file
Query
StringPath to the changelog configuration file in the project’s Git repository. If omitted, uses .gitlab/changelog_config.yml
Example: .gitlab/changelog_config.yml
config_file_ref
Query
StringGit reference, for example a branch, where the changelog configuration file is defined. Defaults to the default branch of the repository
Example: main

Responses

CodeDescriptionSchema
200OKAPIEntitiesChangelog
400Bad Request—
404Not Found—

Add changelog data to file

POST /api/v4/projects/{id}/repository/changelog

Adds changelog data to file.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
Example: 1

Request body (application/json)

PropertyTypeDescription
branchStringName of the branch to commit the changelog changes to. If omitted, defaults to the project’s default branch
Example: main
config_fileStringPath to the changelog configuration file in the project’s Git repository. If omitted, uses .gitlab/changelog_config.yml
Example: .gitlab/changelog_config.yml
config_file_refStringGit reference, for example a branch, where the changelog configuration file is defined. Defaults to the default branch of the repository
Example: main
dateString (date-time)Date and time of the release. Defaults to the current time
Example: 2021-09-20T11:50:22.001+00:00
fileStringFile to commit the changes to
Default: CHANGELOG.md
Example: CHANGELOG.md
fromStringFirst commit in the range of commits, as a SHA, to use for the changelog. This commit is not included in the changelog. If omitted, the most recent stable version tag before version is used
Example: ed899a2f4b50b4370feeea94676502b42383c746
messageStringCommit message to use when committing the changelog changes. If omitted, defaults to Add changelog for version X, where X is the value of the version parameter
Example: Initial commit
toStringLast commit in the range of commits, as a SHA, to use for the changelog. This commit is included in the changelog. If omitted, uses the latest commit on the default branch. For the Add changelog data to file operation, uses the latest commit on branch instead. The range can contain at most 15,000 commits
Example: 6104942438c14ec7bd21c6cd5bd995272b3faff6
trailerStringGit trailer to use for including commits. Case-sensitive: Example does not match example or eXaMpLE
Default: Changelog
Example: Changelog

Responses

CodeDescriptionSchema
200OK—
400Bad Request—
404Not 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

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
Example: 1
from
Query, required
StringRef to compare from. Accepts a commit SHA, branch name, or tag name
Example: main
to
Query, required
StringRef to compare to. Accepts a commit SHA, branch name, or tag name
Example: feature
from_project_id
Query
IntegerID of the project to compare from
Example: 1
straight
Query
BooleanIf true, comparison method is direct comparison between from and to (from..to). If false, compares using merge base (from…to)
Default: false
unidiff
Query
BooleanIf true, presents diffs in the unified diff format
Default: false

Responses

CodeDescriptionSchema
200OKAPIEntitiesCompare
400Bad Request—
404Not Found—

Retrieve contributors metrics

GET /api/v4/projects/{id}/repository/contributors

Retrieves a list of contributors to a specified repository.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
Example: 1
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20
ref
Query
StringName of a repository branch or tag. If omitted, uses the default branch
Example: main
order_by
Query
StringSort results by the specified field
Allowed values: email, name, commits
Default: commits
sort
Query
StringSort results in ascending or descending order
Allowed values: asc, desc
Default: asc

Responses

CodeDescriptionSchema
200OKAPIEntitiesContributor
400Bad Request—
404Not 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

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
Example: 1
from
Query, required
StringThe commit SHA or branch/tag to compare from
Maximum length: 255
Example: main
to
Query, required
StringThe commit SHA or branch/tag to compare to
Maximum length: 255
Example: feature
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20

Responses

CodeDescriptionSchema
200OKArray of APIEntitiesDiffStat
400Bad request—
401Unauthorized—
403Forbidden—
404Not found—
429Too many requests—

Retrieve diverging commit counts between two refs

GET /api/v4/projects/{id}/repository/diverging_commits

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
Example: 1
from
Query, required
StringRef to compare from. Accepts a commit SHA, branch name, or tag name
Maximum length: 255
Example: main
to
Query, required
StringRef to compare to. Accepts a commit SHA, branch name, or tag name
Maximum length: 255
Example: feature
max_count
Query
IntegerMaximum number of commits to count. Use 0 for unlimited
Default: 0
Minimum: 0
Example: 1000

Responses

CodeDescriptionSchema
200OKAPIEntitiesDivergingCommitCount
400Bad request—
401Unauthorized—
403Forbidden—
404Not found—
429Too 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

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
Example: 1
generate
Query
BooleanIf true, generates a new health report. Set this if the endpoint returns 404
Default: false

Responses

CodeDescriptionSchema
200OKAPIEntitiesRepositoryHealth
400Bad Request—
404Not Found—

Retrieve a merge base

GET /api/v4/projects/{id}/repository/merge_base

Retrieves the merge base for two specified commits.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
Example: 1
refs
Query, required
Array of stringsRefs to find the common ancestor of. Accepts multiple refs
Example: ["main","feature"]

Responses

CodeDescriptionSchema
200OKAPIEntitiesCommit
400Bad Request—
404Not 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

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
Example: 1
ref
Query
StringName of a repository branch or tag. If omitted, uses the default branch
Maximum length: 1024
Example: main
path
Query
StringPath inside the repository, used to get the contents of subdirectories
Maximum length: 1024
Example: files/html
recursive
Query
BooleanIf true, returns a recursive tree
Default: false
with_last_commit
Query
BooleanIf true, includes the last commit for each tree entry. Cannot be combined with recursive. Introduced in GitLab 19.3
Default: false
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20
pagination
Query
StringPagination method. keyset uses the keyset-based pagination method. none is valid only if recursive is true
Allowed values: legacy, keyset, none
Default: legacy
page_token
Query
StringTree record ID at which to fetch the next page. Used only with keyset pagination
Example: a1e8f8d745cc87e3a9248358d9352bb7f9a0aeba

Responses

CodeDescriptionSchema
200OKAPIEntitiesTreeObject
400Bad Request—
404404 Project Not Found—

Schemas

Objects returned by the operations above and objects nested in their request bodies.

APIEntitiesBatchBlob

PropertyTypeDescription
contentStringExample: VGhpcyBpcyBhIGZpbGU=
encodingStringExample: base64
pathStringExample: app/models/user.rb
refStringExample: main
sizeIntegerExample: 1476
truncatedBooleanExample: false

APIEntitiesChangedPath

PropertyTypeDescription
new_modeStringExample: 100644
old_modeStringExample: 100644
old_pathStringExample: app/models/user.rb
pathStringExample: app/models/user.rb
statusStringExample: MODIFIED

APIEntitiesChangelog

PropertyTypeDescription
notesStringExample: ## 1.0.0 (2023-01-01)

APIEntitiesCommit

PropertyTypeDescription
author_emailStringExample: john@example.com
author_nameStringExample: John Smith
authored_dateString (date-time)Example: 2012-05-28T04:42:42-07:00
committed_dateString (date-time)Example: 2012-05-28T04:42:42-07:00
committer_emailStringExample: jack@example.com
committer_nameStringExample: Jack Smith
created_atString (date-time)Example: 2017-07-26T11:08:53.000+02:00
extended_trailersObjectExample: {"Signed-off-by":["John Doe \u003cjohndoe@gitlab.com\u003e","Jane Doe \u003cjanedoe@gitlab.com\u003e"]}
idStringExample: 2695effb5807a22ff3d138d593fd856244e155e7
messageStringExample: Initial commit
parent_idsArray of stringsExample: ["2a4b78934375d7f53875269ffd4f45fd83a84ebe"]
short_idStringExample: 2695effb
titleStringExample: Initial commit
trailersObjectExample: {"Merged-By":"Jane Doe janedoe@gitlab.com"}
web_urlStringExample: https://gitlab.example.com/janedoe/gitlab-foss/-/commit/ed899a2f4b50b4370feeea94676502b42383c746

APIEntitiesCompare

PropertyTypeDescription
commitAPIEntitiesCommit—
commitsArray of APIEntitiesCommit—
compare_same_refBoolean—
compare_timeoutBoolean—
diffsArray of APIEntitiesDiff—
web_urlStringExample: https://gitlab.example.com/gitlab/gitlab-foss/-/compare/main...feature

APIEntitiesContributor

PropertyTypeDescription
additionsIntegerExample: 3
commitsIntegerExample: 117
deletionsIntegerExample: 5
emailStringExample: johndoe@example.com
nameStringExample: John Doe

APIEntitiesDiff

PropertyTypeDescription
a_modeStringExample: 100755
b_modeStringExample: 100644
collapsedBoolean—
deleted_fileBoolean—
diffStringExample: @@ -71,6 +71,8 @@\n...
generated_fileBoolean—
new_fileBoolean—
new_pathStringExample: doc/update/5.4-to-6.0.md
old_pathStringExample: doc/update/5.4-to-6.0.md
renamed_fileBoolean—
too_largeBoolean—

APIEntitiesDiffStat

PropertyTypeDescription
additionsIntegerExample: 10
deletionsIntegerExample: 3
old_pathStringExample: app/models/user.rb
pathStringExample: app/models/user.rb

APIEntitiesDivergingCommitCount

PropertyTypeDescription
aheadIntegerExample: 5
behindIntegerExample: 3

APIEntitiesRepositoryHealth

PropertyTypeDescription
alternatesObject—
bitmapAPIEntitiesRepositoryHealthBitmap—
commit_graphAPIEntitiesRepositoryHealthCommitGraph—
is_object_poolBoolean—
last_full_repackAPIEntitiesRepositoryHealthLastFullRepack—
multi_pack_indexAPIEntitiesRepositoryHealthMultiPackIndex—
multi_pack_index_bitmapAPIEntitiesRepositoryHealthBitmap—
objectsAPIEntitiesRepositoryHealthObjects—
referencesAPIEntitiesRepositoryHealthReferences—
sizeInteger—
updated_atString (date-time)Example: 2025-02-24T09:05:50.355Z

APIEntitiesRepositoryHealthBitmap

PropertyTypeDescription
has_hash_cacheBoolean—
has_lookup_tableBoolean—
versionInteger—

APIEntitiesRepositoryHealthCommitGraph

PropertyTypeDescription
commit_graph_chain_lengthInteger—
has_bloom_filtersBoolean—
has_generation_dataBoolean—
has_generation_data_overflowBoolean—

APIEntitiesRepositoryHealthLastFullRepack

PropertyTypeDescription
nanosInteger—
secondsInteger—

APIEntitiesRepositoryHealthMultiPackIndex

PropertyTypeDescription
packfile_countInteger—
versionInteger—

APIEntitiesRepositoryHealthObjects

PropertyTypeDescription
cruft_countInteger—
keep_countInteger—
keep_sizeInteger—
loose_objects_countInteger—
loose_objects_garbage_countInteger—
packfile_countInteger—
recent_sizeInteger—
reverse_index_countInteger—
sizeInteger—
stale_loose_objects_countInteger—
stale_sizeInteger—

APIEntitiesRepositoryHealthReferences

PropertyTypeDescription
loose_countInteger—
packed_sizeInteger—
reference_backendString—

APIEntitiesTreeObject

PropertyTypeDescription
idStringExample: a1e8f8d745cc87e3a9248358d9352bb7f9a0aeba
last_commitAPIEntitiesCommit—
modeStringExample: 040000
nameStringExample: html
pathStringExample: files/html
typeStringExample: tree