3

Is it somehow possible to set the default branch of a Git repository using Visual Studio Team Service REST API? There is an API for repositories and an UI for setting the default branch, but I couldn't find a possibility to set the default branch through the REST API.

Community
  • 1
  • 1
Pascal Berger
  • 4,262
  • 2
  • 30
  • 54

3 Answers3

3

The API can be found here: Update repository

Call:

PATCH https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}?api-version=5.1

With payload:

{
    "defaultBranch": "refs/heads/{branchName}"
}
mhu
  • 17,720
  • 10
  • 62
  • 93
  • 2
    Note that `repositoryId` is a guid which you can get by calling `GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryName}?api-version=5.1` – abatishchev May 19 '20 at 18:42
1

There isn't any way to do this with REST API for now.

Eddie Chen - MSFT
  • 29,708
  • 2
  • 46
  • 60
1

The API now has a way to change the default branch. The documentation is here, under the "Modify a Repository" section.

gnuanu
  • 2,252
  • 3
  • 29
  • 42