Share via


Git trees

TFS 2017 | TFS 2015 | TFS 2013

Note

Looking for REST APIS that support TFS 2018 or later versions? See the Azure DevOps REST API Reference.

api-version = 1.0

Trees are folders in a Git repository.

If you haven't already, look at the information on getting started with these APIs.

Download a tree

Use the request header Accept: application/zip to download a folder and its contents in the zip format.

Accept: application/zip
GET https://{instance}/DefaultCollection/{project}/_apis/repos/git/repositories/{repository}/trees/{objectId}?api-version={version}&fileName={fileName}
Parameter Type Default Notes
URL
instance string TFS server name ({server:port}).
project string ID or name of the project. Optional if specifying an ID for repository.
repository string ID of the repository.
objectId string SHA1 hash of the folder. You can get the objectId of a folder by getting its metadata.
Query
api-version string Version of the API to use.
$format enum Use zip. If not set, defaults to the MIME type set in the Accept header.
fileName string object ID Provide a name to use if a .zip file is returned. If omitted, the zip file is named after the object ID.

Note

Repositories have both a name and an identifier. Identifiers are globally unique, but several projects may contain a repository of the same name. You don't need to include the project if you specify a repository by ID. However, if you specify a repository by name, you must also specify the project (by name or ID).

Get tree metadata

Get the metadata for a tree and its contents.

GET https://{instance}/DefaultCollection/{project}/_apis/git[/{projectId}/repositories/{repository}/trees/{objectId}?api-version={version}&$format=json[&recursive={bool}]
Parameter Type Default Notes
URL
instance string TFS server name ({server:port}).
project string ID or name of the project. Optional if specifying an ID for repository.
repository string ID of the repository.
objectId string SHA1 hash of the folder. You can get the objectId of a folder by getting its metadata.
Query
api-version string Version of the API to use.
$format enum Use json. If not set, defaults to the MIME type set in the Accept header.
recursive bool false Recursively fetch items from each child tree.

Sample request

GET https://mytfsserver/DefaultCollection/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/trees/d1d5c2d49045d52bba6419652d6ecb2cd560dc29?api-version=1.0

Sample response

{
  "objectId": "d1d5c2d49045d52bba6419652d6ecb2cd560dc29",
  "url": "https://mytfsserver/DefaultCollection/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/trees/d1d5c2d49045d52bba6419652d6ecb2cd560dc29",
  "treeEntries": [
    {
      "objectId": "ea6765e1976b9e8a6d4981fd8febebd574a91571",
      "relativePath": "Home",
      "mode": "40000",
      "gitObjectType": "tree",
      "url": "https://mytfsserver/DefaultCollection/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/trees/ea6765e1976b9e8a6d4981fd8febebd574a91571",
      "size": 259
    },
    {
      "objectId": "d1c521e3b401b314d4f9ff17f6cad4652c6a4d14",
      "relativePath": "Shared",
      "mode": "40000",
      "gitObjectType": "tree",
      "url": "https://mytfsserver/DefaultCollection/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/trees/d1c521e3b401b314d4f9ff17f6cad4652c6a4d14",
      "size": 82
    },
    {
      "objectId": "f5dd7df5872eae8c39c9491f67d856dafd609683",
      "relativePath": "Web.config",
      "mode": "100644",
      "gitObjectType": "blob",
      "url": "https://mytfsserver/DefaultCollection/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/blobs/f5dd7df5872eae8c39c9491f67d856dafd609683",
      "size": 1670
    },
    {
      "objectId": "2de62418c07c3ffa833543f484445dbfd0fe68d8",
      "relativePath": "_ViewStart.cshtml",
      "mode": "100644",
      "gitObjectType": "blob",
      "url": "https://mytfsserver/DefaultCollection/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/blobs/2de62418c07c3ffa833543f484445dbfd0fe68d8",
      "size": 54
    }
  ],
  "size": 147,
  "_links": {
    "self": {
      "href": "https://mytfsserver/DefaultCollection/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/trees/d1d5c2d49045d52bba6419652d6ecb2cd560dc29"
    },
    "repository": {
      "href": "https://mytfsserver/DefaultCollection/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249"
    },
    "treeEntries": [
      {
        "href": "https://mytfsserver/DefaultCollection/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/trees/ea6765e1976b9e8a6d4981fd8febebd574a91571"
      },
      {
        "href": "https://mytfsserver/DefaultCollection/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/trees/d1c521e3b401b314d4f9ff17f6cad4652c6a4d14"
      },
      {
        "href": "https://mytfsserver/DefaultCollection/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/blobs/f5dd7df5872eae8c39c9491f67d856dafd609683"
      },
      {
        "href": "https://mytfsserver/DefaultCollection/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/blobs/2de62418c07c3ffa833543f484445dbfd0fe68d8"
      }
    ]
  }
}