Git repositories

Last Update: 7/14/2017

api-version = 1.0

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

There are code samples available for this endpoint.

Get a list of repositories

GET https://{instance}/DefaultCollection/{project}/_apis/git/repositories?api-version={version}
Parameter Type Notes
URL
instance string VS Team Services account ({account}.visualstudio.com) or TFS server ({server:port}).
project string ID or name of the team project. Optional if specifying an ID for repository.
Query
api-version string Version of the API to use.

In your account

Get all the repositories in your Visual Studio Team Services account, rather than a specific project.

Sample request

GET https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories?api-version=1.0

Sample response

Status code: 200
{
  "count": 3,
  "value": [
    {
      "id": "5febef5a-833d-4e14-b9c0-14cb638f91e6",
      "name": "AnotherRepository",
      "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/5febef5a-833d-4e14-b9c0-14cb638f91e6",
      "project": {
        "id": "6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
        "name": "Fabrikam-Fiber-Git",
        "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
        "state": "wellFormed"
      },
      "remoteUrl": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/Fabrikam-Fiber-Git/_git/AnotherRepository"
    },
    {
      "id": "278d5cd2-584d-4b63-824a-2ba458937249",
      "name": "Fabrikam-Fiber-Git",
      "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249",
      "project": {
        "id": "6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
        "name": "Fabrikam-Fiber-Git",
        "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
        "state": "wellFormed"
      },
      "defaultBranch": "refs/heads/master",
      "remoteUrl": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_git/Fabrikam-Fiber-Git"
    },
    {
      "id": "66efb083-777a-4cac-a350-a24b046be6be",
      "name": "TestGit",
      "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/66efb083-777a-4cac-a350-a24b046be6be",
      "project": {
        "id": "281f9a5b-af0d-49b4-a1df-fe6f5e5f84d0",
        "name": "TestGit",
        "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/projects/281f9a5b-af0d-49b4-a1df-fe6f5e5f84d0",
        "state": "wellFormed"
      },
      "defaultBranch": "refs/heads/master",
      "remoteUrl": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_git/TestGit"
    }
  ]
}

Get a repository

GET https://{instance}/DefaultCollection/{project}/_apis/git/repositories/{repository}?api-version={version}
Parameter Type Notes
URL
instance string VS Team Services account ({account}.visualstudio.com) or TFS server ({server:port}).
project string ID or name of the team project. Optional if specifying an ID for repository.
repository string ID or name of the repository.
Query
api-version string Version of the API to use.

By ID

When you get a repository by it's ID, you don't need to specify the project.

Sample request

GET https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/5febef5a-833d-4e14-b9c0-14cb638f91e6?api-version=1.0

Sample response

Status code: 200
{
  "id": "5febef5a-833d-4e14-b9c0-14cb638f91e6",
  "name": "AnotherRepository",
  "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/5febef5a-833d-4e14-b9c0-14cb638f91e6",
  "project": {
    "id": "6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
    "name": "Fabrikam-Fiber-Git",
    "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
    "state": "wellFormed",
    "revision": 293012730
  },
  "defaultBranch": "refs/heads/master",
  "remoteUrl": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/Fabrikam-Fiber-Git/_git/AnotherRepository",
  "_links": {
    "self": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/5febef5a-833d-4e14-b9c0-14cb638f91e6"
    },
    "project": {
      "href": "vstfs:///Classification/TeamProject/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c"
    },
    "web": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/Fabrikam-Fiber-Git/_git/AnotherRepository"
    },
    "commits": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/5febef5a-833d-4e14-b9c0-14cb638f91e6/commits"
    },
    "refs": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/5febef5a-833d-4e14-b9c0-14cb638f91e6/refs"
    },
    "pullRequests": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/5febef5a-833d-4e14-b9c0-14cb638f91e6/pullRequests"
    },
    "items": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/5febef5a-833d-4e14-b9c0-14cb638f91e6/items"
    },
    "pushes": {
      "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/5febef5a-833d-4e14-b9c0-14cb638f91e6/pushes"
    }
  }
}

By remote URL

You can also get a repository with only the clone URL of the repo:

GET {gitCloneUrl}/vsts/info

Sample request

GET https://fabrikam-fiber-inc.visualstudio.com/_git/FabrikamCloud/vsts/info

Sample response

Status code: 200
{
  "serverUrl": "https://fabrikam-fiber-inc.visualstudio.com",
  "collection": {
    "id": "e22ddea7-989e-455d-b46a-67e991b04714",
    "name": "fabrikam-fiber-inc",
    "url": "https://fabrikam-fiber-inc.visualstudio.com/_apis/projectCollections/e22ddea7-989e-455d-b46a-67e991b04714"
  },
  "repository": {
    "id": "2f3d611a-f012-4b39-b157-8db63f380226",
    "name": "FabrikamCloud",
    "url": "https://fabrikam-fiber-inc.visualstudio.com/_apis/git/repositories/2f3d611a-f012-4b39-b157-8db63f380226",
    "project": {
      "id": "3b3ae425-0079-421f-9101-bcf15d6df041",
      "name": "FabrikamCloud",
      "url": "https://fabrikam-fiber-inc.visualstudio.com/_apis/projects/3b3ae425-0079-421f-9101-bcf15d6df041",
      "state": 1,
      "revision": 411518573
    },
    "remoteUrl": "https://fabrikam-fiber-inc.visualstudio.com/FabrikamCloud/_git/FabrikamCloud"
  }
}

Create a repository

Create a Git repository in a team project.

POST https://{instance}/DefaultCollection/{project}/_apis/git/repositories/?api-version={version}
Content-Type: application/json
{
  "name": {string},
  "project": {
    "id": {guid}
  }
}
Parameter Type Notes
URL
instance string VS Team Services account ({account}.visualstudio.com) or TFS server ({server:port}).
project string ID or name of the team project. Optional if specifying an ID in the body.
Query
api-version string Version of the API to use.
Body
name string Name of the repository.
project string Name or ID team project. Do not include if project specified in the URL.

Sample request

POST https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories?api-version=1.0
Content-Type: application/json
{
  "name": "AnotherRepository",
  "project": {
    "id": "6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c"
  }
}

Sample response

Status code: 201
{
  "id": "5febef5a-833d-4e14-b9c0-14cb638f91e6",
  "name": "AnotherRepository",
  "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/5febef5a-833d-4e14-b9c0-14cb638f91e6",
  "project": {
    "id": "6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
    "name": "Fabrikam-Fiber-Git",
    "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
    "state": "wellFormed"
  },
  "remoteUrl": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/Fabrikam-Fiber-Git/_git/AnotherRepository"
}

Modify a repository

PATCH https://{instance}/DefaultCollection/{project}/_apis/git/repositories/{repository}?api-version={version}
Content-Type: application/json
{
  "name": {string},
  "defaultBranch", {string}
}
Parameter Type Notes
URL
instance string VS Team Services account ({account}.visualstudio.com) or TFS server ({server:port}).
project string ID or name of the team project. Optional if specifying an ID for repository.
repository string ID of the repository.
Query
api-version string Version of the API to use.
Body
name string New name of the repository.
defaultBranch string New default branch of the repository.

Sample request

PATCH https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/5febef5a-833d-4e14-b9c0-14cb638f91e6?api-version=1.0
Content-Type: application/json
{
  "name": "RenamedRepository",
  "defaultBranch": "refs/heads/live"
}

Sample response

Status code: 200
{
  "id": "5febef5a-833d-4e14-b9c0-14cb638f91e6",
  "name": "RenamedRepository",
  "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/5febef5a-833d-4e14-b9c0-14cb638f91e6",
  "project": {
    "id": "6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
    "name": "Fabrikam-Fiber-Git",
    "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
    "state": "wellFormed"
  },
  "defaultBranch": "refs/heads/live",
  "remoteUrl": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/Fabrikam-Fiber-Git/_git/RenamedRepository",
  "type": "normal"
}

Delete a repository

Permanently delete a repository.

DELETE https://{instance}/DefaultCollection/{project}/_apis/git/repositories/{repository}?api-version={version}
Parameter Type Notes
URL
instance string VS Team Services account ({account}.visualstudio.com) or TFS server ({server:port}).
project string ID or name of the team project. Optional if specifying an ID for repository.
repository string ID of the repository.
Query
api-version string Version of the API to use.