---
title: "Create or update file contents"
method: PUT
path: "/repos/{owner}/{repo}/contents/{path}"
tags: ["repos"]
---

# Create or update file contents

`PUT /repos/{owner}/{repo}/contents/{path}`

Creates a new file or replaces an existing file in a repository. You must authenticate using an access token with the `repo` scope to use this endpoint. If you want to modify files in the `.github/workflows` directory, you must authenticate using an access token with the `workflow` scope.

**Note:** If you use this endpoint and the "[Delete a file](https://docs.github.com/enterprise-server@3.7/rest/repos/contents/#delete-a-file)" endpoint in parallel, the concurrent requests will conflict and you will receive errors. You must use these endpoints serially instead.

## Path parameters

- `owner` string, required
- `repo` string, required
- `path` string, required

## Request body

- object
  - `message` string, required — The commit message.
  - `content` string, required — The new file content, using Base64 encoding.
  - `sha` string — **Required if you are updating a file**. The blob SHA of the file being replaced.
  - `branch` string — The branch name. Default: the repository’s default branch.
  - `committer` object — The person that committed the file. Default: the authenticated user.
    - `name` string, required — The name of the author or committer of the commit. You'll receive a `422` status code if `name` is omitted.
    - `email` string, required — The email of the author or committer of the commit. You'll receive a `422` status code if `email` is omitted.
    - `date` string
  - `author` object — The author of the file. Default: The `committer` or the authenticated user if you omit `committer`.
    - `name` string, required — The name of the author or committer of the commit. You'll receive a `422` status code if `name` is omitted.
    - `email` string, required — The email of the author or committer of the commit. You'll receive a `422` status code if `email` is omitted.
    - `date` string

## Response `200`

Response

- FileCommit — File Commit
  - `content` object, nullable, required
    - `name` string
    - `path` string
    - `sha` string
    - `size` integer
    - `url` string
    - `html_url` string
    - `git_url` string
    - `download_url` string
    - `type` string
    - `_links` object
      - `self` string
      - `git` string
      - `html` string
  - `commit` object, required
    - `sha` string
    - `node_id` string
    - `url` string
    - `html_url` string
    - `author` object
      - `date` string
      - `name` string
      - `email` string
    - `committer` object
      - `date` string
      - `name` string
      - `email` string
    - `message` string
    - `tree` object
      - `url` string
      - `sha` string
    - `parents` object[]
      - `url` string
      - `html_url` string
      - `sha` string
    - `verification` object
      - `verified` boolean
      - `reason` string
      - `signature` string, nullable
      - `payload` string, nullable

## Other responses

- `201` — Response
- `404` — Resource not found
- `409` — Conflict
- `422` — Validation failed, or the endpoint has been spammed.

---

[API](https://skmtc.net/github/apis/github-v3-rest-api-6.md) · [All operations](https://skmtc.net/github/apis/github-v3-rest-api-6/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/github/github-v3-rest-api-6/versions/15db3fa0759b/schema)
