GitHub get-tree API limits and recursivity


As per the get-tree API (GET /repos/:owner/:repo/git/trees/:tree_sha):

“If truncated is true, the number of items in the tree array exceeded our maximum limit. If you need to fetch more items, you can clone the repository and iterate over the Git data locally.”

Another online post mentions a GitHub API limit of 1,000 items per tree (

Is there an exact number of items allowed in a tree? If yes, how many?

An example I tried:

The root directory containing, 4,000 files, and two subdirectories, containing 4,000 files each.

  • /
  • ----
  • ---- 4,000 files in /
  • ---- /dir1
  • -------- 4,000 files in /dir1
  • ---- /dir2
  • -------- 4,000 files in /dir2

Calling get-tree API is returning the whole list of 12,003 items, which makes the limit of 1,000 items not possible. The attribute “truncated” is always returned in the response with a value of false.

Another question for this example: If recursive was passed to the API with a value of 0, shouldn’t the response exclude the 8,000 files from the two subdirectories? Regardless if recursive is passed with a value of 0 or 1, it is always returning all files in the response.

Hi @alhaddad-nasry,

Thanks for being here :slight_smile:

We actually have a limit of 100,000 entries. If the recursive parameter is supplied, we will read and return a maximum of 7 MB worth of entries from git ls-tree.

The limit was bumped from 1,000 entries to 100,000 in 2014. The issue linked to in the OP may have been working on slightly outdated assumptions.

This all said, keep in mind that 100,000 is the current limit, but it could change anytime in the future.

I hope this helps! 

1 Like


Wouldn’t it be nice to include if get tree (recursive) had the support of:

*) Max depth. 

*) Simple file pattern matching.



Is there a limit when creating a new tree? When doing a POST of a new tree with around 1.5K the tree is created successfully but when attempting with a 20K tree then I get a 502. Have been looking for documentation about this but have not been lucky so far.

Thanks in advance!

1 Like

@nadiajoyce, Is there a documentation where it specify the max limit for Tree API?
It seems that, limits are not included in the : page.