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, added as a suffix to the path, for example archive.zip. One of bz2, gz, tar, tar.bz2, tar.gz, tb2, tbz, tbz2, tgz, or zip. Default is tar.gz
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

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

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. 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

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. 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

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. 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

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. Can include or omit the v prefix: 1.0.0 and v1.0.0 give the same result
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. Tags in X.Y.Z or vX.Y.Z format are recognized, and pre-release tags such as v1.0.0-pre1 are ignored. If no such tag exists, an error is returned and you must set from
Example: ed899a2f4b50b4370feeea94676502b42383c746
to
Query
StringLast commit in the range of commits, as a SHA or a branch or tag name, 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. Introduced in GitLab 18.2
Example: main

Responses

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

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. Introduced in GitLab 18.2
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. Tags in X.Y.Z or vX.Y.Z format are recognized, and pre-release tags such as v1.0.0-pre1 are ignored. If no such tag exists, an error is returned and you must set from
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 or a branch or tag name, 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. 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

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—
403Forbidden—
404Not Found—
503Service 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

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. Introduced in GitLab 17.4
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. 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

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

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

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. This feature was introduced in GitLab 17.10.

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, the common ancestor, of two or more refs, such as commit SHAs, branch names, or tags.

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
contentStringBase64-encoded content of the blob
Example: VGhpcyBpcyBhIGZpbGU=
encodingStringEncoding of content. Always base64
Example: base64
pathStringPath of the file in the repository
Example: app/models/user.rb
refStringBranch, tag, or commit the file was read from
Example: main
sizeIntegerFull size of the blob in bytes
Example: 1476
truncatedBooleanWhether content is truncated to the first 1 MB of the blob
Example: false

APIEntitiesChangedPath

PropertyTypeDescription
new_modeStringNew file mode
Example: 100644
old_modeStringPrevious file mode
Example: 100644
old_pathStringPrevious path of the file. Same as path unless the file was renamed or copied
Example: app/models/user.rb
pathStringPath of the file
Example: app/models/user.rb
statusStringChange type. One of ADDED, MODIFIED, DELETED, RENAMED, TYPE_CHANGE, or COPIED
Example: MODIFIED

APIEntitiesChangelog

PropertyTypeDescription
notesStringGenerated changelog data in Markdown format
Example: ## 1.0.0 (2023-01-01)

APIEntitiesCommit

PropertyTypeDescription
author_emailStringEmail address of the commit author
Example: john@example.com
author_nameStringName of the commit author
Example: John Smith
authored_dateString (date-time)Date and time when the commit was authored
Example: 2012-05-28T04:42:42-07:00
committed_dateString (date-time)Date and time when the commit was committed
Example: 2012-05-28T04:42:42-07:00
committer_emailStringEmail address of the committer
Example: jack@example.com
committer_nameStringName of the committer
Example: Jack Smith
created_atString (date-time)Date and time when the commit was created. Identical to committed_date
Example: 2017-07-26T11:08:53.000+02:00
extended_trailersObjectGit trailers parsed from the commit message, with every value for each key
Example: {"Signed-off-by":["John Doe \u003cjohndoe@gitlab.com\u003e","Jane Doe \u003cjanedoe@gitlab.com\u003e"]}
idStringFull SHA of the commit
Example: 2695effb5807a22ff3d138d593fd856244e155e7
messageStringFull commit message
Example: Initial commit
parent_idsArray of stringsSHAs of the parent commits
Example: ["2a4b78934375d7f53875269ffd4f45fd83a84ebe"]
short_idStringShort SHA of the commit
Example: 2695effb
titleStringTitle of the commit message
Example: Initial commit
trailersObjectGit trailers parsed from the commit message. Duplicate keys include the last value only
Example: {"Merged-By":"Jane Doe janedoe@gitlab.com"}
web_urlStringURL to view the commit in the GitLab UI
Example: https://gitlab.example.com/janedoe/gitlab-foss/-/commit/ed899a2f4b50b4370feeea94676502b42383c746

APIEntitiesCompare

PropertyTypeDescription
commitAPIEntitiesCommitLatest commit in the comparison
commitsArray of APIEntitiesCommitCommits between the two references. Not truncated when compare_timeout is true. For unauthenticated requests, contains at most the 100 most recent commits in the range. Behind a feature flag named compare_api_anonymous_commits_limit, disabled by default
compare_same_refBooleanIf true, from and to resolve to the same commit
compare_timeoutBooleanIf true, the comparison exceeded size limits or timed out, and diffs might be incomplete
diffsArray of APIEntitiesDiffFile differences between the two references
web_urlStringURL to view the comparison in the GitLab UI
Example: https://gitlab.example.com/gitlab/gitlab-foss/-/compare/main...feature

APIEntitiesContributor

PropertyTypeDescription
additionsIntegerNumber of lines added by the contributor
Example: 3
commitsIntegerNumber of commits by the contributor
Example: 117
deletionsIntegerNumber of lines deleted by the contributor
Example: 5
emailStringEmail address of the contributor
Example: johndoe@example.com
nameStringName of the contributor
Example: John Doe

APIEntitiesDiff

PropertyTypeDescription
a_modeStringOld file mode of the file
Example: 100755
b_modeStringNew file mode of the file
Example: 100644
collapsedBooleanIf true, the file diff is excluded but can be fetched on request. Introduced in GitLab 18.4
deleted_fileBooleanIf true, the file was removed
diffStringDiff of the changes made to the file
Example: @@ -71,6 +71,8 @@\n...
generated_fileBooleanIf true, the file is marked as generated
new_fileBooleanIf true, the file was added
new_pathStringNew path of the file
Example: doc/update/5.4-to-6.0.md
old_pathStringOld path of the file
Example: doc/update/5.4-to-6.0.md
renamed_fileBooleanIf true, the file was renamed
too_largeBooleanIf true, the file diff is excluded and cannot be retrieved. Introduced in GitLab 18.4

APIEntitiesDiffStat

PropertyTypeDescription
additionsIntegerNumber of added lines
Example: 10
deletionsIntegerNumber of deleted lines
Example: 3
old_pathStringPrevious path of the file. Differs from path when the file was renamed
Example: app/models/user.rb
pathStringPath of the file
Example: app/models/user.rb

APIEntitiesDivergingCommitCount

PropertyTypeDescription
aheadIntegerNumber of commits in to that are not in from
Example: 5
behindIntegerNumber of commits in from that are not in to
Example: 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