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. You can access this endpoint without authentication if the repository is publicly accessible. For blobs larger than 10 MB, this endpoint has a rate limit of 5 requests every minute for each project. For text files not stored as valid UTF-8 in Git, content is converted to UTF-8 before Base64 encoding. In that case, size is the raw blob size, which might differ from the length of the decoded content, and content_sha256 is the hash of the converted content, not the raw blob. To retrieve the exact bytes stored in Git, use the raw file endpoint.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String | ID or URL- Example: gitlab- |
file_Path, | String | URL-lib%2Example: lib%2 |
refQuery, | String | Commit SHA or name of a repository branch or tag.HEAD to use the default branchExample: main |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | — |
400 | Bad Request | — |
404 | Not 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. Requests larger than 300 MB by default are rejected. Requests larger than 20 MB are rate-limited to 3 requests every 30 seconds for each user.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String | ID or URL- Example: gitlab- |
file_Path, | String | URL-lib%2Example: lib%2 |
Request body (multipart/form-data)
| Property | Type | Description |
|---|---|---|
fileRequired | String (binary) | The file content to be created (generated by Multipart middleware) |
Responses
| Code | Description | Schema |
|---|---|---|
201 | Created | — |
400 | Bad Request | — |
404 | Not 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. Requests larger than 300 MB by default are rejected. Requests larger than 20 MB are rate-limited to 3 requests every 30 seconds for each user. If the commit fails, returns 400 Bad Request with an error message. Possible causes are a file_path that contains /../, new file contents that are identical to the current contents, or a git push to the branch while the edit was in progress.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String | ID or URL- Example: gitlab- |
file_Path, | String | URL-lib%2Example: lib%2 |
Request body (multipart/form-data)
| Property | Type | Description |
|---|---|---|
fileRequired | String (binary) | The file content to be updated (generated by Multipart middleware) |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | — |
400 | Bad Request | — |
404 | Not 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
| Name | Type | Description |
|---|---|---|
idPath, | String | ID or URL- Example: gitlab- |
file_Path, | String | URL-lib%2Example: lib%2 |
branchQuery, | String | Name of the branch to commit the deletion into.start_ to create a new branchExample: main |
commit_Query, | String | Commit message Example: Initial commit |
start_Query | String | Name of the base branch to create the branch from Example: main |
author_Query | String | Email address of the commit author Example: johndoe@example. |
author_Query | String | Name of the commit author Example: John Doe |
last_Query | String | Last known file commit ID Example: 2695effb5807a22ff3d1 |
Responses
| Code | Description | Schema |
|---|---|---|
204 | No Content | — |
400 | Bad Request | — |
404 | Not Found | — |
Retrieve file metadata
HEAD /api/v4/projects/{id}/repository/files/{file_path}
Retrieves metadata for a specified file in a repository. Uses the HEAD method and returns the metadata in X-Gitlab-* response headers, such as X-Gitlab-Blob-Id, X-Gitlab-Commit-Id, X-Gitlab-Content-Sha256, X-Gitlab-File-Name, X-Gitlab-Last-Commit-Id, X-Gitlab-Ref, and X-Gitlab-Size.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String | ID or URL- Example: gitlab- |
file_Path, | String | URL-lib%2Example: lib%2 |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
refRequired | String | Commit SHA or name of a repository branch or tag Example: main |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | — |
400 | Bad Request | — |
404 | Not 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. This endpoint is rate-limited for each authenticated user for a given project, and for each IP address for unauthenticated requests. On GitLab Self-Managed and GitLab Dedicated, an administrator can change these limits in the application settings. The default limits are 400 requests every minute for each user and project, set by project_repositories_blame_limit, and 400 requests every minute for each IP address, set by project_repositories_blame_unauthenticated_limit. A limit of 0 disables it. HEAD requests do not count toward these limits. The GraphQL blame field on RepositoryBlob shares these limits.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String | ID or URL- Example: gitlab- |
file_Path, | String | URL-lib%2Example: lib%2 |
refQuery, | String | Commit SHA or name of a repository branch or tag.HEAD to use the default branchExample: main |
rangeQuery | Object | Range of lines to return blame information for |
range[start]Query, | Integer | First line number of the range to blame Minimum: 1 |
range[end]Query, | Integer | Last line number of the range to blame Minimum: 1 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not Found | — |
429 | Too many requests | — |
Retrieve file blame metadata
HEAD /api/v4/projects/{id}/repository/files/{file_path}/blame
Retrieves blame metadata for lines in a specified file. Uses the HEAD method and returns the metadata in X-Gitlab-* response headers, such as X-Gitlab-Blob-Id, X-Gitlab-Commit-Id, X-Gitlab-Content-Sha256, X-Gitlab-File-Name, X-Gitlab-Last-Commit-Id, X-Gitlab-Ref, and X-Gitlab-Size.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String | ID or URL- Example: gitlab- |
file_Path, | String | URL-lib%2Example: lib%2 |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
refRequired | String | Commit SHA or name of a repository branch or tag Example: main |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | — |
400 | Bad Request | — |
404 | Not 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. To get only the file metadata, use the HEAD method on the file endpoint.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String | ID or URL- Example: gitlab- |
file_Path, | String | URL-lib%2Example: lib%2 |
refQuery | String | Commit SHA or name of a repository branch or tag.HEAD of the projectExample: main |
lfsQuery | Boolean | If true,Default: false |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | String (binary) (application/) |
400 | Bad Request | — |
404 | Not Found | — |
Schemas
Objects returned by the operations above and objects nested in their request bodies.
APIEntitiesBlameRange
| Property | Type | Description |
|---|---|---|
commit | APIEntities | Commit that last changed the lines in this blame range |
lines | Array of strings | Lines of the file in this blame range Example: ["lorem ipsum"] |
APIEntitiesBlameRangeCommit
| 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 |
id | String | Example:2695effb5807a22ff3d1 |
message | String | Example:Initial commit |
parent_ | Array of strings | Example:["2a4b78934375d7f53875 |