Use this API to manage repository files. You can also configure rate limits for this API.

Retrieve a file from a repository

GET /api/v4/projects/{id}/repository/files/{file_path}

Retrieves information about a specified file in a repository. This includes information like the name, size, and the file contents. File content is Base64 encoded.

Parameters

NameTypeDescription
id
Path, required
StringID or URL-encoded path of the project
Example: gitlab-org/gitlab
file_path
Path, required
StringURL-encoded full path to the file, for example lib%2Fclass%2Erb
Example: lib%2Fclass%2Erb
ref
Query, required
StringCommit SHA or name of a repository branch or tag
Example: main

Responses

CodeDescriptionSchema
200OK—
400Bad Request—
404Not Found—

Create a file in a repository

POST /api/v4/projects/{id}/repository/files/{file_path}

Creates a file in a specified repository. Use the Commits API to create multiple files with a single request.

Parameters

NameTypeDescription
id
Path, required
StringID or URL-encoded path of the project
Example: gitlab-org/gitlab
file_path
Path, required
StringURL-encoded full path to the file, for example lib%2Fclass%2Erb
Example: lib%2Fclass%2Erb

Request body (multipart/form-data)

PropertyTypeDescription
file
Required
String (binary)The file content to be created (generated by Multipart middleware)

Responses

CodeDescriptionSchema
201Created—
400Bad Request—
404Not Found—

Update a file in a repository

PUT /api/v4/projects/{id}/repository/files/{file_path}

Updates a specified file in a repository. Use the Commits API to update multiple files with a single request.

Parameters

NameTypeDescription
id
Path, required
StringID or URL-encoded path of the project
Example: gitlab-org/gitlab
file_path
Path, required
StringURL-encoded full path to the file, for example lib%2Fclass%2Erb
Example: lib%2Fclass%2Erb

Request body (multipart/form-data)

PropertyTypeDescription
file
Required
String (binary)The file content to be updated (generated by Multipart middleware)

Responses

CodeDescriptionSchema
200OK—
400Bad Request—
404Not Found—

Delete a file in a repository

DELETE /api/v4/projects/{id}/repository/files/{file_path}

Deletes a specified file in a repository. Use the Commits API to delete multiple files with a single request.

Parameters

NameTypeDescription
id
Path, required
StringID or URL-encoded path of the project
Example: gitlab-org/gitlab
file_path
Path, required
StringURL-encoded full path to the file, for example lib%2Fclass%2Erb
Example: lib%2Fclass%2Erb
branch
Query, required
StringName of the branch to commit the deletion into. Combine with start_branch to create a new branch
Example: main
commit_message
Query, required
StringCommit message
Example: Initial commit
start_branch
Query
StringName of the base branch to create the branch from
Example: main
author_email
Query
StringEmail address of the commit author
Example: johndoe@example.com
author_name
Query
StringName of the commit author
Example: John Doe
last_commit_id
Query
StringLast known file commit ID
Example: 2695effb5807a22ff3d138d593fd856244e155e7

Responses

CodeDescriptionSchema
204No Content—
400Bad Request—
404Not Found—

Retrieve file metadata

HEAD /api/v4/projects/{id}/repository/files/{file_path}

Retrieves metadata for a specified file in a repository.

Parameters

NameTypeDescription
id
Path, required
StringID or URL-encoded path of the project
Example: gitlab-org/gitlab
file_path
Path, required
StringURL-encoded full path to the file, for example lib%2Fclass%2Erb
Example: lib%2Fclass%2Erb

Request body (application/json)

PropertyTypeDescription
ref
Required
StringCommit SHA or name of a repository branch or tag
Example: main

Responses

CodeDescriptionSchema
200OK—
400Bad Request—
404Not Found—

Retrieve file blame history from a repository

GET /api/v4/projects/{id}/repository/files/{file_path}/blame

Retrieves blame history for a specified file in a repository. Each blame range contains lines and their corresponding commit information.

Parameters

NameTypeDescription
id
Path, required
StringID or URL-encoded path of the project
Example: gitlab-org/gitlab
file_path
Path, required
StringURL-encoded full path to the file, for example lib%2Fclass%2Erb
Example: lib%2Fclass%2Erb
ref
Query, required
StringCommit SHA or name of a repository branch or tag
Example: main
range
Query
ObjectRange of lines to return blame information for
range[start]
Query, required
IntegerFirst line number of the range to blame
Minimum: 1
range[end]
Query, required
IntegerLast line number of the range to blame
Minimum: 1

Responses

CodeDescriptionSchema
200OKAPIEntitiesBlameRange
400Bad Request—
404Not Found—

Retrieve file blame metadata

HEAD /api/v4/projects/{id}/repository/files/{file_path}/blame

Retrieves blame metadata for lines in a specified file.

Parameters

NameTypeDescription
id
Path, required
StringID or URL-encoded path of the project
Example: gitlab-org/gitlab
file_path
Path, required
StringURL-encoded full path to the file, for example lib%2Fclass%2Erb
Example: lib%2Fclass%2Erb

Request body (application/json)

PropertyTypeDescription
ref
Required
StringCommit SHA or name of a repository branch or tag
Example: main

Responses

CodeDescriptionSchema
200OK—
400Bad Request—
404Not Found—

Retrieve a raw file from a repository

GET /api/v4/projects/{id}/repository/files/{file_path}/raw

Retrieves the raw file contents for a specified file in a repository.

Parameters

NameTypeDescription
id
Path, required
StringID or URL-encoded path of the project
Example: gitlab-org/gitlab
file_path
Path, required
StringURL-encoded full path to the file, for example lib%2Fclass%2Erb
Example: lib%2Fclass%2Erb
ref
Query
StringCommit SHA or name of a repository branch or tag
Example: main
lfs
Query
BooleanIf true, returns the Git LFS file contents instead of the pointer. Ignored if the file isn’t tracked by Git LFS
Default: false

Responses

CodeDescriptionSchema
200OKString (binary) (application/octet-stream)
400Bad Request—
404Not Found—

Schemas

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

APIEntitiesBlameRange

PropertyTypeDescription
commitAPIEntitiesBlameRangeCommit—
linesArray of stringsExample: ["lorem ipsum"]

APIEntitiesBlameRangeCommit

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
idStringExample: 2695effb5807a22ff3d138d593fd856244e155e7
messageStringExample: Initial commit
parent_idsArray of stringsExample: ["2a4b78934375d7f53875269ffd4f45fd83a84ebe"]