Create a file in a repository
const url = 'https://gitea.com/api/v1/repos/example/example/contents/example';const options = { method: 'POST', headers: {Authorization: 'Basic <credentials>', 'Content-Type': 'application/json'}, body: '{"author":{"email":"hello@example.com","name":"example"},"branch":"example","committer":{"email":"hello@example.com","name":"example"},"content":"example","dates":{"author":"2026-04-15T12:00:00Z","committer":"2026-04-15T12:00:00Z"},"force_push":true,"message":"example","new_branch":"example","signoff":true}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://gitea.com/api/v1/repos/example/example/contents/example \ --header 'Authorization: Basic <credentials>' \ --header 'Content-Type: application/json' \ --data '{ "author": { "email": "hello@example.com", "name": "example" }, "branch": "example", "committer": { "email": "hello@example.com", "name": "example" }, "content": "example", "dates": { "author": "2026-04-15T12:00:00Z", "committer": "2026-04-15T12:00:00Z" }, "force_push": true, "message": "example", "new_branch": "example", "signoff": true }'Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”Owner of the repo
Name of the repo
Path of the file to create
Request Body
Section titled “Request Body”CreateFileOptions options for creating a file
Note: author and committer are optional (if only one is given, it will be used for the other, otherwise the authenticated user will be used)
object
Identity for a person’s identity like an author or committer
object
Name is the person’s name
Branch (optional) is the base branch for the changes. If not supplied, the default branch is used
Identity for a person’s identity like an author or committer
object
Name is the person’s name
Content must be base64 encoded
CommitDateOptions store dates for GIT_AUTHOR_DATE and GIT_COMMITTER_DATE
object
Force_push (optional) will do a force-push if the new branch already exists
Message (optional) is the commit message of the changes. If not supplied, a default message will be used
New_branch (optional) will make a new branch from base branch for the changes. If not supplied, the changes will be committed to the base branch
Add a Signed-off-by trailer by the committer at the end of the commit log message.
Examplegenerated
{ "author": { "email": "hello@example.com", "name": "example" }, "branch": "example", "committer": { "email": "hello@example.com", "name": "example" }, "content": "example", "dates": { "author": "2026-04-15T12:00:00Z", "committer": "2026-04-15T12:00:00Z" }, "force_push": true, "message": "example", "new_branch": "example", "signoff": true}Responses
Section titled “Responses”FileResponse
FileResponse contains information about a repo’s file
object
object
object
Date is the commit date in string format
Name is the person’s name
object
Date is the commit date in string format
Name is the person’s name
HTMLURL is the web URL for viewing this commit
Message is the commit message
Parents contains parent commit metadata
object
SHA is the commit SHA hash
URL is the API URL for the commit
SHA is the commit SHA hash
object
SHA is the commit SHA hash
URL is the API URL for the commit
URL is the API URL for the commit
ContentsResponse contains information about a repo’s entry’s (dir, file, symlink, submodule) metadata and content
object
FileLinksResponse contains the links for a repo’s file
object
GitURL is the Git API URL for this file
HTMLURL is the web URL for this file
Self is the API URL for this file
content is populated when type is file, otherwise null
DownloadURL is the direct download URL for this file
encoding is populated when type is file, otherwise null
GitURL is the Git API URL for this blob or tree
HTMLURL is the web URL for this file or directory
LastCommitMessage is the message of the last commit that affected this file
LastCommitSHA is the SHA of the last commit that affected this file
LfsOid is the Git LFS object ID if this file is stored in LFS
LfsSize is the file size if this file is stored in LFS
Name is the file or directory name
Path is the full path to the file or directory
SHA is the Git blob or tree SHA
Size is the file size in bytes
submodule_git_url is populated when type is submodule, otherwise null
target is populated when type is symlink, otherwise null
type will be file, dir, symlink, or submodule
URL is the API URL for this file or directory
PayloadCommitVerification represents the GPG verification of a commit
object
The signed payload content
The reason for the verification status
The GPG signature of the commit
PayloadUser represents the author or committer of a commit
object
Full name of the commit author
Username of the user
Whether the commit signature is verified
Examplegenerated
{ "commit": { "author": { "date": "example", "email": "hello@example.com", "name": "example" }, "committer": { "date": "example", "email": "hello@example.com", "name": "example" }, "created": "2026-04-15T12:00:00Z", "html_url": "example", "message": "example", "parents": [ { "created": "2026-04-15T12:00:00Z", "sha": "example", "url": "example" } ], "sha": "example", "tree": { "created": "2026-04-15T12:00:00Z", "sha": "example", "url": "example" }, "url": "example" }, "content": { "_links": { "git": "example", "html": "example", "self": "example" }, "content": "example", "download_url": "example", "encoding": "example", "git_url": "example", "html_url": "example", "last_author_date": "2026-04-15T12:00:00Z", "last_commit_message": "example", "last_commit_sha": "example", "last_committer_date": "2026-04-15T12:00:00Z", "lfs_oid": "example", "lfs_size": 1, "name": "example", "path": "example", "sha": "example", "size": 1, "submodule_git_url": "example", "target": "example", "type": "example", "url": "example" }, "verification": { "payload": "example", "reason": "example", "signature": "example", "signer": { "email": "hello@example.com", "name": "example", "username": "example" }, "verified": true }}APIError is error format response
Headers
Section titled “Headers”APINotFound is a not found empty response
APIError is error format response
Headers
Section titled “Headers”APIRepoArchivedError is an error that is raised when an archived repo should be modified