Create or update a file
create_or_update_fileCreates a repository file or replaces its full UTF-8 content in one commit; pass the current SHA to safely update an existing file, or omit it to create a new one.
Instructions
Create a file, or replace one's content, as a single commit (owner/repo/path/content; requires write mode). content is the whole file as UTF-8 text. To update, pass the file's current sha from get_file_contents; without sha the file is created, and the forge refuses if it already exists. A stale sha is refused too, so a change made meanwhile is not overwritten. Commits to branch (default: the default branch), or to new_branch created from it — the way to prepare a pull request. Answers with the file's new sha and the commit.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"owner": "<owner>",
"repo": "<repo>",
"path": "<path>",
"content": "<content>"
},
"name": "create_or_update_file"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sha | No | To update an existing file: its current blob SHA, from `get_file_contents`. Omit it to create a new file. A stale SHA is refused, so a change made meanwhile is not overwritten. | |
| path | Yes | File path from the repository root, e.g. `docs/setup.md`. | |
| repo | Yes | Repository name. | |
| owner | Yes | Repository owner. | |
| branch | No | Branch to commit to. Defaults to the repository's default branch. | |
| content | Yes | The whole new content, as UTF-8 text. | |
| message | No | Commit message. The forge composes one when absent. | |
| new_branch | No | Create this branch from `branch` and commit there instead — the way to propose a change as a pull request. |