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
| Name | Type | Description |
|---|---|---|
idPath, | String | The project ID Example: gitlab- |
file_Path, | String | The URL- Example: lib%2 |
refQuery, | String | The name of branch, Example: 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.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String | The project ID Example: gitlab- |
file_Path, | String | The URL- Example: 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.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String | The project ID Example: gitlab- |
file_Path, | String | The URL- Example: 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 | The project ID Example: gitlab- |
file_Path, | String | The URL- Example: lib%2 |
branchQuery, | String | Name of the branch to commit into.start_Example: main |
commit_Query, | String | Commit message Example: Initial commit |
start_Query | String | Name of the branch to start the new commit from Example: main |
author_Query | String | The email of the author Example: johndoe@example. |
author_Query | String | The name of the 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.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String | The project ID Example: gitlab- |
file_Path, | String | The URL- Example: lib%2 |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
refRequired | String | The name of branch, 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.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String | The project ID Example: gitlab- |
file_Path, | String | The URL- Example: lib%2 |
refQuery, | String | The name of branch, Example: main |
rangeQuery | Object | Object that contains the blame range |
range[start]Query, | Integer | The first line of the range to blame Minimum: 1 |
range[end]Query, | Integer | The last line of the range to blame Minimum: 1 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not 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
| Name | Type | Description |
|---|---|---|
idPath, | String | The project ID Example: gitlab- |
file_Path, | String | The URL- Example: lib%2 |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
refRequired | String | The name of branch, 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.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String | The project ID Example: gitlab- |
file_Path, | String | The URL- Example: lib%2 |
refQuery | String | The name of branch, Example: main |
lfsQuery | Boolean | Retrieve binary data for a file that is an lfs pointer 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 | — |
lines | Array of strings | 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 |