# Get a tree

From **GitHub v3 REST API**.

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

Returns a single tree using the SHA1 value 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.

## Parameters

### `owner`

- Location: path
- Required: true
- Type: `string`

### `repo`

- Location: path
- Required: true
- Type: `string`

### `tree_sha`

- Location: path
- Required: true
- Type: `string`

### `recursive`

- Location: query
- Required: false
- Type: `string`

Setting this parameter to any value returns the objects or subtrees referenced by the tree specified in `:tree_sha`. For example, setting `recursive` to any of the following will enable returning objects or subtrees: `0`, `1`, `"true"`, and `"false"`. Omit this parameter to prevent recursively returning objects or subtrees.

## Responses

### `200`

Response

### `application/json`

- Type: `object`

The hierarchy between files in a Git repository.

```json
{
  "sha": "9fb037999f264ba9a7fc6274d15fa3ae2ab98312",
  "tree": [
    {
      "mode": "100644",
      "path": "file.rb",
      "sha": "44b4fc6d56897b048c772eb4087f854f46256132",
      "size": 30,
      "type": "blob",
      "url": "https://api.github.com/repos/octocat/Hello-World/git/blobs/44b4fc6d56897b048c772eb4087f854f46256132"
    },
    {
      "mode": "040000",
      "path": "subdir",
      "sha": "f484d249c660418515fb01c2b9662073663c242e",
      "type": "tree",
      "url": "https://api.github.com/repos/octocat/Hello-World/git/blobs/f484d249c660418515fb01c2b9662073663c242e"
    },
    {
      "mode": "100755",
      "path": "exec_file",
      "sha": "45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
      "size": 75,
      "type": "blob",
      "url": "https://api.github.com/repos/octocat/Hello-World/git/blobs/45b983be36b73c0788dc9cbcb76cbb80fc7bb057"
    }
  ],
  "truncated": false,
  "url": "https://api.github.com/repos/octocat/Hello-World/trees/9fb037999f264ba9a7fc6274d15fa3ae2ab98312"
}
```

```json
{"description":"The hierarchy between files in a Git repository.","properties":{"sha":{"type":"string"},"tree":{"description":"Objects specifying a tree structure","example":[{"mode":"100644","path":"file.rb","properties":{"mode":{"type":"string"},"path":{"type":"string"},"sha":{"type":"string"},"size":{"type":"integer"},"type":{"type":"string"},"url":{"type":"string"}},"required":["path","mode","type","sha","url","size"],"sha":"44b4fc6d56897b048c772eb4087f854f46256132","size":30,"type":"blob","url":"https://api.github.com/repos/octocat/Hello-World/git/blobs/44b4fc6d56897b048c772eb4087f854f46256132"}],"items":{"properties":{"mode":{"example":"040000","type":"string"},"path":{"example":"test/file.rb","type":"string"},"sha":{"example":"23f6827669e43831def8a7ad935069c8bd418261","type":"string"},"size":{"example":12,"type":"integer"},"type":{"example":"tree","type":"string"},"url":{"example":"https://api.github.com/repos/owner-482f3203ecf01f67e9deb18e/BBB_Private_Repo/git/blobs/23f6827669e43831def8a7ad935069c8bd418261","type":"string"}},"type":"object"},"type":"array"},"truncated":{"type":"boolean"},"url":{"format":"uri","type":"string"}},"required":["sha","url","tree","truncated"],"title":"Git Tree","type":"object"}
```

### `404`

Resource not found

### `application/json`

- Type: `object`

Basic Error

```json
{"description":"Basic Error","properties":{"documentation_url":{"type":"string"},"message":{"type":"string"},"status":{"type":"string"},"url":{"type":"string"}},"title":"Basic Error","type":"object"}
```

### `422`

Validation failed

### `application/json`

- Type: `object`

Validation Error

```json
{"description":"Validation Error","properties":{"documentation_url":{"type":"string"},"errors":{"items":{"properties":{"code":{"type":"string"},"field":{"type":"string"},"index":{"type":"integer"},"message":{"type":"string"},"resource":{"type":"string"},"value":{"oneOf":[{"nullable":true,"type":"string"},{"nullable":true,"type":"integer"},{"items":{"type":"string"},"nullable":true,"type":"array"}]}},"required":["code"],"type":"object"},"type":"array"},"message":{"type":"string"}},"required":["message","documentation_url"],"title":"Validation Error","type":"object"}
```

## Request examples

### cURL

```shell
curl --request GET \
  --url {protocol}://{hostname}/api/v3/repos/{owner}/{repo}/git/trees/{tree_sha}
```
