Sample - GitHub REST API
PUT/repos/{owner}/{repo}/contents/{path}

Create or update file contents

Creates a new file or replaces an existing file in a repository.

[!NOTE] If you use this endpoint and the "Delete a file" endpoint in parallel, the concurrent requests will conflict and you will receive errors. You must use these endpoints serially instead.

OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint. The workflow scope is also required in order to modify files in the .github/workflows directory.

  • RetriesRetries up to 2×, 500ms backoff, 30s timeout.

3 parameters · 6 body fields
ownerstringrequired
The account owner of the repository. The name is not case sensitive.
repostringrequired
The name of the repository without the `.git` extension. The name is not case sensitive.
pathstringrequired
path parameter
messagestringrequired
The commit message.
contentstringrequired
The new file content, using Base64 encoding.
shastringoptional
**Required if you are updating a file**. The blob SHA of the file being replaced.
branchstringoptional
The branch name. Default: the repository’s default branch.
committerobjectoptional
The person that committed the file. Default: the authenticated user.
authorobjectoptional
The author of the file. Default: The `committer` or the authenticated user if you omit `committer`.

5 status codes
200Response
contentobjectrequired
commitobjectrequired
201Response
contentobjectrequired
commitobjectrequired
404Resource not found
messagestringoptional
documentation_urlstringoptional
urlstringoptional
statusstringoptional
409Conflict
messagestringoptional
documentation_urlstringoptional
urlstringoptional
statusstringoptional
422Validation failed, or the endpoint has been spammed.
messagestringrequired
documentation_urlstringrequired
errorsarray<object>optional

Error handling

A 404 is returned: Resource not found. A 409 is returned: Conflict. A 422 is returned: Validation failed, or the endpoint has been spammed.