> ## Documentation Index
> Fetch the complete documentation index at: https://gogs.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Create or update a file

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



## OpenAPI

````yaml PUT /repos/{owner}/{repo}/contents/{path}
openapi: 3.0.3
info:
  title: Gogs API
  version: v1
  description: >-
    RESTful API for interacting with your Gogs instance. Follows a format
    similar to the GitHub REST API v3.
servers:
  - url: https://gogs.example.com/api/v1
security:
  - AccessToken: []
tags:
  - name: Repositories
    description: Create, search, and manage repositories, branches, commits, and contents
  - name: Collaborators and Deploy Keys
    description: Manage repository collaborators and deploy keys
  - name: Releases
    description: List repository releases
  - name: Webhooks
    description: Create, edit, and delete repository webhooks
  - name: Issues
    description: Manage issues, comments, labels, and milestones
  - name: Users
    description: Search users, manage access tokens, emails, followers, and public keys
  - name: Organizations
    description: Manage organizations, members, and teams
  - name: Administration
    description: Site administration endpoints (requires admin privileges)
  - name: Miscellaneous
    description: Markdown rendering and Git data endpoints
paths:
  /repos/{owner}/{repo}/contents/{path}:
    put:
      tags:
        - Repositories
      summary: Create or update a file
      description: >-
        Creates or updates a file in the repository. The content must be base64
        encoded.
      operationId: putContents
      parameters:
        - name: owner
          in: path
          required: true
          schema:
            type: string
          description: Owner of the repository
        - name: repo
          in: path
          required: true
          schema:
            type: string
          description: Name of the repository
        - name: path
          in: path
          required: true
          schema:
            type: string
          description: Path of the file to create or update
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                message:
                  type: string
                  description: Commit message
                content:
                  type: string
                  description: Base64-encoded file content
                branch:
                  type: string
                  description: >-
                    Branch to commit to. Defaults to the repository's default
                    branch.
              required:
                - message
                - content
      responses:
        '201':
          description: File created or updated successfully.
          content:
            application/json:
              schema:
                type: object
                properties:
                  content:
                    $ref: '#/components/schemas/Content'
                  commit:
                    $ref: '#/components/schemas/Commit'
        '404':
          description: Repository not found.
        '422':
          description: Validation error.
components:
  schemas:
    Content:
      type: object
      properties:
        type:
          type: string
          enum:
            - file
            - dir
            - symlink
            - submodule
        encoding:
          type: string
        size:
          type: integer
        name:
          type: string
        path:
          type: string
        content:
          type: string
        sha:
          type: string
        url:
          type: string
        git_url:
          type: string
        html_url:
          type: string
        download_url:
          type: string
        _links:
          type: object
          properties:
            git:
              type: string
            self:
              type: string
            html:
              type: string
    Commit:
      type: object
      properties:
        url:
          type: string
        sha:
          type: string
        html_url:
          type: string
        commit:
          type: object
          properties:
            url:
              type: string
            message:
              type: string
            author:
              type: object
              properties:
                name:
                  type: string
                email:
                  type: string
                date:
                  type: string
            committer:
              type: object
              properties:
                name:
                  type: string
                email:
                  type: string
                date:
                  type: string
            tree:
              type: object
              properties:
                url:
                  type: string
                sha:
                  type: string
        author:
          $ref: '#/components/schemas/User'
        committer:
          $ref: '#/components/schemas/User'
        parents:
          type: array
          items:
            type: object
            properties:
              url:
                type: string
              sha:
                type: string
    User:
      type: object
      properties:
        id:
          type: integer
        username:
          type: string
        login:
          type: string
          description: Alias of username for GitHub API compatibility
        full_name:
          type: string
        email:
          type: string
          format: email
        avatar_url:
          type: string
  securitySchemes:
    AccessToken:
      type: apiKey
      in: header
      name: Authorization
      description: 'Personal access token. Use format: token {YOUR_ACCESS_TOKEN}'

````