v50

latestOpenAPI 3.0.3MITraw.githubusercontent.com2024-03-2585861610.1 MB
git

Create a tree

The tree creation API accepts nested entries. If you specify both a tree and a nested path modifying that tree, this endpoint will overwrite the contents of the tree with the new path contents, and create a new tree structure.

If you use this endpoint to add, delete, or modify the file contents in a tree, you will need to commit the tree and then update a branch to point to the commit. For more information see "Create a commit" and "Update a reference."

Returns an error if you try to delete a file that does not exist.

post/repos/{owner}/{repo}/git/trees

Path parameters

ownerstring required

The account owner of the repository. The name is not case sensitive.

repostring required

The name of the repository without the .git extension. The name is not case sensitive.

Request body

base_treestring

The SHA1 of an existing Git tree object which will be used as the base for the new tree. If provided, a new Git tree object will be created from entries in the Git tree object pointed to by base_tree and entries defined in the tree parameter. Entries defined in the tree parameter will overwrite items from base_tree with the same path. If you're creating new changes on a branch, then normally you'd set base_tree to the SHA1 of the Git tree object of the current latest commit on the branch you're working on. If not provided, GitHub will create a new Git tree object from only the entries defined in the tree parameter. If you create a new commit pointing to such a tree, then all files which were a part of the parent commit's tree and were not defined in the tree parameter will be listed as deleted by the new commit.

Response

Response

shastring required
urlstring uri required
truncatedboolean required

Example response

{
  "tree": [
    {
      "path": "file.rb",
      "mode": "100644",
      "type": "blob",
      "size": 30,
      "sha": "44b4fc6d56897b048c772eb4087f854f46256132",
      "url": "https://api.github.com/repos/octocat/Hello-World/git/blobs/44b4fc6d56897b048c772eb4087f854f46256132",
      "properties": {
        "path": {
          "type": "string"
        },
        "mode": {
          "type": "string"
        },
        "type": {
          "type": "string"
        },
        "size": {
          "type": "integer"
        },
        "sha": {
          "type": "string"
        },
        "url": {
          "type": "string"
        }
      },
      "required": [
        "path",
        "mode",
        "type",
        "sha",
        "url",
        "size"
      ]
    }
  ]
}