REST API endpoints for Git trees

Use the REST API to interact with tree objects in your Git database on GitHub.

About Git trees

A Git tree object creates the hierarchy between files in a Git repository. You can use the Git tree object to create the relationship between directories and the files they contain. These endpoints allow you to read and write tree objects to your Git database on GitHub.

Note

Most endpoints use Authorization: Bearer <YOUR-TOKEN> and Accept: application/vnd.github+json headers, plus X-GitHub-Api-Version: 2026-03-10. Curl examples below omit these standard headers for brevity.

Create a tree

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

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.

Parameters

Headers

Path and query parameters

Body parameters

HTTP response status codes

Code examples

Example

Request:

curl -L \
  -X POST \
  https://api.github.com/repos/OWNER/REPO/git/trees \
  -d '{
  "base_tree": "9fb037999f264ba9a7fc6274d15fa3ae2ab98312",
  "tree": [
    {
      "path": "file.rb",
      "mode": "100644",
      "type": "blob",
      "sha": "44b4fc6d56897b048c772eb4087f854f46256132"
    }
  ]
}'

Response schema (Status: 201):

Get a tree

GET /repos/{owner}/{repo}/git/trees/{tree_sha}

Returns a single tree using the SHA1 value or ref name for that tree.
If truncated is true in the response then the number of items in the tree array exceeded our maximum limit. If you need to fetch more items, use the non-recursive method of fetching trees, and fetch one sub-tree at a time.
Note

The limit for the tree array is 100,000 entries with a maximum size of 7 MB when using the recursive parameter.

Parameters

Headers

Path and query parameters

HTTP response status codes

Code examples

Example 1: Status Code 200

Request:

curl -L \
  -X GET \
  https://api.github.com/repos/OWNER/REPO/git/trees/TREE_SHA

Response schema (Status: 200):

Same response schema as Create a tree.

Example 2: Status Code 200

Request:

curl -L \
  -X GET \
  https://api.github.com/repos/OWNER/REPO/git/trees/TREE_SHA

Response schema (Status: 200):

Same response schema as Create a tree.