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."
POST /repos/:owner/:repo/git/trees
| Name | Type | Description |
|---|---|---|
tree |
array of objects |
Required. Objects (of path, mode, type, and sha) specifying a tree structure. |
base_tree |
string |
The SHA1 of the tree you want to update with new data. If you don't set this, the commit will be created on top of everything; however, it will only contain your change, the rest of your files will show up as deleted. |
tree object| Name | Type | Description |
|---|---|---|
path |
string |
The file referenced in the tree. |
mode |
string |
The file mode; one of 100644 for file (blob), 100755 for executable (blob), 040000 for subdirectory (tree), 160000 for submodule (commit), or 120000 for a blob that specifies the path of a symlink. |
type |
string |
Either blob, tree, or commit. |
sha |
string or null
|
The SHA1 checksum ID of the object in the tree. Also called tree.sha. If the value is null then the file will be deleted. Note: Use either tree.sha or content to specify the contents of the entry. Using both tree.sha and content will return an error. |
content |
string |
The content you want this file to have. GitHub will write this blob out and use that SHA for this entry. Use either this, or tree.sha. Note: Use either tree.sha or content to specify the contents of the entry. Using both tree.sha and content will return an error. |
{
"base_tree": "9fb037999f264ba9a7fc6274d15fa3ae2ab98312",
"tree": [
{
"path": "file.rb",
"mode": "100644",
"type": "blob",
"sha": "44b4fc6d56897b048c772eb4087f854f46256132"
}
]
}
Status: 201 Created
Location: https://api.github.com/repos/octocat/Hello-World/trees/cd8274d15fa3ae2ab983129fb037999f264ba9a7
{
"sha": "cd8274d15fa3ae2ab983129fb037999f264ba9a7",
"url": "https://api.github.com/repos/octocat/Hello-World/trees/cd8274d15fa3ae2ab983129fb037999f264ba9a7",
"tree": [
{
"path": "file.rb",
"mode": "100644",
"type": "blob",
"size": 132,
"sha": "7c258a9869f33c1e1e1f74fbb32f07c86cb5a75b",
"url": "https://api.github.com/repos/octocat/Hello-World/git/blobs/7c258a9869f33c1e1e1f74fbb32f07c86cb5a75b"
}
]
}