# Create or update file contents

From **GitHub v3 REST API**.

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

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

## Parameters

### `owner`

- Location: path
- Required: true
- Type: `string`

### `repo`

- Location: path
- Required: true
- Type: `string`

### `path`

- Location: path
- Required: true
- Type: `string`

path parameter

## Request body

- Required: true
### `application/json`

- Type: `object`

```json
{
  "committer": {
    "email": "octocat@github.com",
    "name": "Monalisa Octocat"
  },
  "content": "bXkgbmV3IGZpbGUgY29udGVudHM=",
  "message": "my commit message"
}
```

```json
{"properties":{"author":{"description":"The author of the file. Default: The `committer` or the authenticated user if you omit `committer`.","properties":{"date":{"example":"\"2013-01-15T17:13:22+05:00\"","type":"string"},"email":{"description":"The email of the author or committer of the commit. You'll receive a `422` status code if `email` is omitted.","type":"string"},"name":{"description":"The name of the author or committer of the commit. You'll receive a `422` status code if `name` is omitted.","type":"string"}},"required":["name","email"],"type":"object"},"branch":{"description":"The branch name. Default: the repository’s default branch (usually `master`)","type":"string"},"committer":{"description":"The person that committed the file. Default: the authenticated user.","properties":{"date":{"example":"\"2013-01-05T13:13:22+05:00\"","type":"string"},"email":{"description":"The email of the author or committer of the commit. You'll receive a `422` status code if `email` is omitted.","type":"string"},"name":{"description":"The name of the author or committer of the commit. You'll receive a `422` status code if `name` is omitted.","type":"string"}},"required":["name","email"],"type":"object"},"content":{"description":"The new file content, using Base64 encoding.","type":"string"},"message":{"description":"The commit message.","type":"string"},"sha":{"description":"**Required if you are updating a file**. The blob SHA of the file being replaced.","type":"string"}},"required":["message","content"],"type":"object"}
```

## Responses

### `200`

Response

### `application/json`

- Type: `object`

File Commit

```json
{
  "commit": {
    "author": {
      "date": "2014-11-07T22:01:45Z",
      "email": "octocat@github.com",
      "name": "Monalisa Octocat"
    },
    "committer": {
      "date": "2014-11-07T22:01:45Z",
      "email": "octocat@github.com",
      "name": "Monalisa Octocat"
    },
    "html_url": "https://github.com/octocat/Hello-World/git/commit/18a43cd8e1e3a79c786e3d808a73d23b6d212b16",
    "message": "my commit message",
    "node_id": "MDY6Q29tbWl0MThhNDNjZDhlMWUzYTc5Yzc4NmUzZDgwOGE3M2QyM2I2ZDIxMmIxNg==",
    "parents": [
      {
        "html_url": "https://github.com/octocat/Hello-World/git/commit/da5a433788da5c255edad7979b328b67d79f53f6",
        "sha": "da5a433788da5c255edad7979b328b67d79f53f6",
        "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/da5a433788da5c255edad7979b328b67d79f53f6"
      }
    ],
    "sha": "18a43cd8e1e3a79c786e3d808a73d23b6d212b16",
    "tree": {
      "sha": "9a21f8e2018f42ffcf369b24d2cd20bc25c9e66f",
      "url": "https://api.github.com/repos/octocat/Hello-World/git/trees/9a21f8e2018f42ffcf369b24d2cd20bc25c9e66f"
    },
    "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/18a43cd8e1e3a79c786e3d808a73d23b6d212b16",
    "verification": {
      "payload": null,
      "reason": "unsigned",
      "signature": null,
      "verified": false
    }
  },
  "content": {
    "_links": {
      "git": "https://api.github.com/repos/octocat/Hello-World/git/blobs/a56507ed892d05a37c6d6128c260937ea4d287bd",
      "html": "https://github.com/octocat/Hello-World/blob/master/notes/hello.txt",
      "self": "https://api.github.com/repos/octocat/Hello-World/contents/notes/hello.txt"
    },
    "download_url": "https://raw.githubusercontent.com/octocat/HelloWorld/master/notes/hello.txt",
    "git_url": "https://api.github.com/repos/octocat/Hello-World/git/blobs/a56507ed892d05a37c6d6128c260937ea4d287bd",
    "html_url": "https://github.com/octocat/Hello-World/blob/master/notes/hello.txt",
    "name": "hello.txt",
    "path": "notes/hello.txt",
    "sha": "a56507ed892d05a37c6d6128c260937ea4d287bd",
    "size": 9,
    "type": "file",
    "url": "https://api.github.com/repos/octocat/Hello-World/contents/notes/hello.txt"
  }
}
```

```json
{"description":"File Commit","properties":{"commit":{"properties":{"author":{"properties":{"date":{"type":"string"},"email":{"type":"string"},"name":{"type":"string"}},"type":"object"},"committer":{"properties":{"date":{"type":"string"},"email":{"type":"string"},"name":{"type":"string"}},"type":"object"},"html_url":{"type":"string"},"message":{"type":"string"},"node_id":{"type":"string"},"parents":{"items":{"properties":{"html_url":{"type":"string"},"sha":{"type":"string"},"url":{"type":"string"}},"type":"object"},"type":"array"},"sha":{"type":"string"},"tree":{"properties":{"sha":{"type":"string"},"url":{"type":"string"}},"type":"object"},"url":{"type":"string"},"verification":{"properties":{"payload":{"nullable":true,"type":"string"},"reason":{"type":"string"},"signature":{"nullable":true,"type":"string"},"verified":{"type":"boolean"}},"type":"object"}},"type":"object"},"content":{"nullable":true,"properties":{"_links":{"properties":{"git":{"type":"string"},"html":{"type":"string"},"self":{"type":"string"}},"type":"object"},"download_url":{"type":"string"},"git_url":{"type":"string"},"html_url":{"type":"string"},"name":{"type":"string"},"path":{"type":"string"},"sha":{"type":"string"},"size":{"type":"integer"},"type":{"type":"string"},"url":{"type":"string"}},"type":"object"}},"required":["content","commit"],"title":"File Commit","type":"object"}
```

### `201`

Response

### `application/json`

- Type: `object`

File Commit

```json
{
  "commit": {
    "author": {
      "date": "2014-11-07T22:01:45Z",
      "email": "octocat@github.com",
      "name": "Monalisa Octocat"
    },
    "committer": {
      "date": "2014-11-07T22:01:45Z",
      "email": "octocat@github.com",
      "name": "Monalisa Octocat"
    },
    "html_url": "https://github.com/octocat/Hello-World/git/commit/7638417db6d59f3c431d3e1f261cc637155684cd",
    "message": "my commit message",
    "node_id": "MDY6Q29tbWl0NzYzODQxN2RiNmQ1OWYzYzQzMWQzZTFmMjYxY2M2MzcxNTU2ODRjZA==",
    "parents": [
      {
        "html_url": "https://github.com/octocat/Hello-World/git/commit/1acc419d4d6a9ce985db7be48c6349a0475975b5",
        "sha": "1acc419d4d6a9ce985db7be48c6349a0475975b5",
        "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/1acc419d4d6a9ce985db7be48c6349a0475975b5"
      }
    ],
    "sha": "7638417db6d59f3c431d3e1f261cc637155684cd",
    "tree": {
      "sha": "691272480426f78a0138979dd3ce63b77f706feb",
      "url": "https://api.github.com/repos/octocat/Hello-World/git/trees/691272480426f78a0138979dd3ce63b77f706feb"
    },
    "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/7638417db6d59f3c431d3e1f261cc637155684cd",
    "verification": {
      "payload": null,
      "reason": "unsigned",
      "signature": null,
      "verified": false
    }
  },
  "content": {
    "_links": {
      "git": "https://api.github.com/repos/octocat/Hello-World/git/blobs/95b966ae1c166bd92f8ae7d1c313e738c731dfc3",
      "html": "https://github.com/octocat/Hello-World/blob/master/notes/hello.txt",
      "self": "https://api.github.com/repos/octocat/Hello-World/contents/notes/hello.txt"
    },
    "download_url": "https://raw.githubusercontent.com/octocat/HelloWorld/master/notes/hello.txt",
    "git_url": "https://api.github.com/repos/octocat/Hello-World/git/blobs/95b966ae1c166bd92f8ae7d1c313e738c731dfc3",
    "html_url": "https://github.com/octocat/Hello-World/blob/master/notes/hello.txt",
    "name": "hello.txt",
    "path": "notes/hello.txt",
    "sha": "95b966ae1c166bd92f8ae7d1c313e738c731dfc3",
    "size": 9,
    "type": "file",
    "url": "https://api.github.com/repos/octocat/Hello-World/contents/notes/hello.txt"
  }
}
```

```json
{"description":"File Commit","properties":{"commit":{"properties":{"author":{"properties":{"date":{"type":"string"},"email":{"type":"string"},"name":{"type":"string"}},"type":"object"},"committer":{"properties":{"date":{"type":"string"},"email":{"type":"string"},"name":{"type":"string"}},"type":"object"},"html_url":{"type":"string"},"message":{"type":"string"},"node_id":{"type":"string"},"parents":{"items":{"properties":{"html_url":{"type":"string"},"sha":{"type":"string"},"url":{"type":"string"}},"type":"object"},"type":"array"},"sha":{"type":"string"},"tree":{"properties":{"sha":{"type":"string"},"url":{"type":"string"}},"type":"object"},"url":{"type":"string"},"verification":{"properties":{"payload":{"nullable":true,"type":"string"},"reason":{"type":"string"},"signature":{"nullable":true,"type":"string"},"verified":{"type":"boolean"}},"type":"object"}},"type":"object"},"content":{"nullable":true,"properties":{"_links":{"properties":{"git":{"type":"string"},"html":{"type":"string"},"self":{"type":"string"}},"type":"object"},"download_url":{"type":"string"},"git_url":{"type":"string"},"html_url":{"type":"string"},"name":{"type":"string"},"path":{"type":"string"},"sha":{"type":"string"},"size":{"type":"integer"},"type":{"type":"string"},"url":{"type":"string"}},"type":"object"}},"required":["content","commit"],"title":"File Commit","type":"object"}
```

### `404`

Resource not found

### `application/json`

- Type: `object`

Basic Error

```json
{"description":"Basic Error","properties":{"documentation_url":{"type":"string"},"message":{"type":"string"},"status":{"type":"string"},"url":{"type":"string"}},"title":"Basic Error","type":"object"}
```

### `409`

Conflict

### `application/json`

- Type: `object`

Basic Error

```json
{"description":"Basic Error","properties":{"documentation_url":{"type":"string"},"message":{"type":"string"},"status":{"type":"string"},"url":{"type":"string"}},"title":"Basic Error","type":"object"}
```

### `422`

Validation failed

### `application/json`

- Type: `object`

Validation Error

```json
{"description":"Validation Error","properties":{"documentation_url":{"type":"string"},"errors":{"items":{"properties":{"code":{"type":"string"},"field":{"type":"string"},"index":{"type":"integer"},"message":{"type":"string"},"resource":{"type":"string"},"value":{"oneOf":[{"nullable":true,"type":"string"},{"nullable":true,"type":"integer"},{"items":{"type":"string"},"nullable":true,"type":"array"}]}},"required":["code"],"type":"object"},"type":"array"},"message":{"type":"string"}},"required":["message","documentation_url"],"title":"Validation Error","type":"object"}
```

## Request examples

### cURL

```shell
curl --request PUT \
  --url {protocol}://{hostname}/api/v3/repos/{owner}/{repo}/contents/{path} \
  --header 'content-type: application/json' \
  --data '{
  "committer": {
    "email": "octocat@github.com",
    "name": "Monalisa Octocat"
  },
  "content": "bXkgbmV3IGZpbGUgY29udGVudHM=",
  "message": "my commit message"
}'
```
