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 integerThe ID or URL-encoded path of the project
Example: 1
sha
Query
StringThe commit sha of the archive to be downloaded
Example: 7d70e02340bac451f281cecf0a980907974bd8be
ref_type
Query
StringType of ref in sha, heads (branch) or tags (tag)
Allowed values: heads, tags
format
Query
StringThe archive format
Example: tar.gz
path
Query
StringSubfolder of the repository to be downloaded
Example: files/archives
include_lfs_blobs
Query
BooleanUsed to exclude LFS objects from archive
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 integerThe ID or URL-encoded path of the project
Example: 1

Request body (application/json)

PropertyTypeDescription
files
Required
Array of objectsArray of file objects to retrieve (max 20)
files[].path
Required
StringThe file path
Example: app/models/user.rb
files[].refStringThe branch, tag, or commit. Defaults to the default branch
Example: main

Responses

CodeDescriptionSchema
200OKAPIEntitiesBatchBlob
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 integerThe ID or URL-encoded path of the project
Example: 1
sha
Path, required
StringThe commit hash
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 integerThe ID or URL-encoded path of the project
Example: 1
sha
Path, required
StringThe commit hash
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 integerThe ID 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
IntegerCurrent page number
Default: 1
Example: 1
per_page
Query
IntegerNumber of items per page
Default: 20
Example: 20

Responses

CodeDescriptionSchema
200OKAPIEntitiesChangedPath
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 integerThe ID or URL-encoded path of the project
Example: 1
version
Query, required
StringThe version of the release, using the 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
StringThe first commit in the range of commits to use for the changelog
Example: ed899a2f4b50b4370feeea94676502b42383c746
to
Query
StringThe last commit in the range of commits to use for the changelog
Example: 6104942438c14ec7bd21c6cd5bd995272b3faff6
date
Query
String (date-time)The date and time of the release
Example: 2021-09-20T11:50:22.001+00:00
trailer
Query
StringThe Git trailer to use for determining if commits are to be included in the changelog
Default: Changelog
Example: Changelog
config_file
Query
StringThe file path to the configuration file as stored in the project’s Git repository. Defaults to ‘.gitlab/changelog_config.yml’
Example: .gitlab/changelog_config.yml
config_file_ref
Query
StringThe git reference (for example, branch) where the changelog configuration file is defined. Defaults to the default repository branch
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 integerThe ID or URL-encoded path of the project
Example: 1

Request body (application/json)

PropertyTypeDescription
branchStringThe branch to commit the changelog changes to
Example: main
config_fileStringThe file path to the configuration file as stored in the project’s Git repository. Defaults to ‘.gitlab/changelog_config.yml’
Example: .gitlab/changelog_config.yml
config_file_refStringThe git reference (for example, branch) where the changelog configuration file is defined. Defaults to the default repository branch
Example: main
dateString (date-time)The date and time of the release
Example: 2021-09-20T11:50:22.001+00:00
fileStringThe file to commit the changelog changes to
Default: CHANGELOG.md
Example: CHANGELOG.md
fromStringThe first commit in the range of commits to use for the changelog
Example: ed899a2f4b50b4370feeea94676502b42383c746
messageStringThe commit message to use when committing the changelog
Example: Initial commit
toStringThe last commit in the range of commits to use for the changelog
Example: 6104942438c14ec7bd21c6cd5bd995272b3faff6
trailerStringThe Git trailer to use for determining if commits are to be included in the changelog
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 integerThe ID or URL-encoded path of the project
Example: 1
from
Query, required
StringThe commit, branch name, or tag name to start comparison
Example: main
to
Query, required
StringThe commit, branch name, or tag name to stop comparison
Example: feature
from_project_id
Query
IntegerThe project to compare from
Example: 1
straight
Query
BooleanComparison method, true for direct comparison between from and to (from..to), false to compare using merge base (from…to)
Default: false
unidiff
Query
BooleanA diff in a 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 integerThe ID or URL-encoded path of the project
Example: 1
page
Query
IntegerCurrent page number
Default: 1
Example: 1
per_page
Query
IntegerNumber of items per page
Default: 20
Example: 20
ref
Query
StringThe name of a repository branch or tag, if not given the default branch is used
Example: main
order_by
Query
StringReturn contributors ordered by name or email or commits
Allowed values: email, name, commits
Default: commits
sort
Query
StringSort by asc (ascending) or desc (descending)
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 integerThe ID 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
IntegerCurrent page number
Default: 1
Example: 1
per_page
Query
IntegerNumber of items per page
Default: 20
Example: 20

Responses

CodeDescriptionSchema
200OKAPIEntitiesDiffStat
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 integerThe ID or URL-encoded path of the project
Example: 1
from
Query, required
StringThe ref to compare from
Maximum length: 255
Example: main
to
Query, required
StringThe ref to compare to
Maximum length: 255
Example: feature
max_count
Query
IntegerMaximum number of commits to count. 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 integerThe ID or URL-encoded path of the project
Example: 1
generate
Query
BooleanTriggers a new health report to be generated
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 integerThe ID or URL-encoded path of the project
Example: 1
refs
Query, required
Array of stringsThe refs to find the common ancestor of, multiple refs can be passed
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 integerThe ID or URL-encoded path of the project
Example: 1
ref
Query
StringThe name of a repository branch or tag, if not given the default branch is used
Maximum length: 1024
Example: main
path
Query
StringThe path of the tree
Maximum length: 1024
Example: files/html
recursive
Query
BooleanUsed to get a recursive tree
Default: false
with_last_commit
Query
BooleanInclude the last commit for each tree entry. Cannot be combined with “recursive”
Default: false
page
Query
IntegerCurrent page number
Default: 1
Example: 1
per_page
Query
IntegerNumber of items per page
Default: 20
Example: 20
pagination
Query
StringSpecify the pagination method (“none” is only valid if “recursive” is true)
Allowed values: legacy, keyset, none
Default: legacy
page_token
Query
StringRecord from which to start the 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