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

# Create or update a file

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

Creates or updates a file in the repository. The content must be base64 encoded.

## Path parameters

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

## Request body

- object
  - `message` string, required — Commit message
  - `content` string, required — Base64-encoded file content
  - `branch` string — Branch to commit to. Defaults to the repository's default branch.

## Response `201`

File created or updated successfully.

- object
  - `content` Content
    - `type` 'file' | 'dir' | 'symlink' | 'submodule'
    - `encoding` string
    - `size` integer
    - `name` string
    - `path` string
    - `content` string
    - `sha` string
    - `url` string
    - `git_url` string
    - `html_url` string
    - `download_url` string
    - `_links` object
      - `git` string
      - `self` string
      - `html` string
  - `commit` Commit
    - `url` string
    - `sha` string
    - `html_url` string
    - `commit` object
      - `url` string
      - `message` string
      - `author` object
        - `name` string
        - `email` string
        - `date` string
      - `committer` object
        - `name` string
        - `email` string
        - `date` string
      - `tree` object
        - `url` string
        - `sha` string
    - `author` User
      - `id` integer
      - `username` string
      - `login` string — Alias of username for GitHub API compatibility
      - `full_name` string
      - `email` string, email
      - `avatar_url` string
    - `committer` User
      - `id` integer
      - `username` string
      - `login` string — Alias of username for GitHub API compatibility
      - `full_name` string
      - `email` string, email
      - `avatar_url` string
    - `parents` object[]
      - `url` string
      - `sha` string

## Other responses

- `404` — Repository not found.
- `422` — Validation error.

---

[API](https://skmtc.net/gogs/apis/gogs-api.md) · [All operations](https://skmtc.net/gogs/apis/gogs-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/gogs/gogs-api/revisions/87e2da32266c/schema)
