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.
Asked
Active
Viewed 1,892 times
3
-
Related (not duplicate) question: https://stackoverflow.com/questions/1485578/change-a-git-remote-head-to-point-to-something-besides-master – Maximillian Laumeister Dec 17 '15 at 20:00
3 Answers
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
-
2Note 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
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

user8328009
- 11
- 1
-
-
Answers shouldn't only consist of links. If you add the sample available in the link to the answer I can accept this as the answer. – Pascal Berger Jul 19 '17 at 15:34