Programmatically set default branch name for new Azure repositories

Viewed 511

With recent changes introduced in Azure repositories the default branch name will be changed to "main" instead of "master". However Microsoft provided a feature to set the default branch name for the repositories which will be created in the future.

enter image description here

This feature can be easily turn on/off using the web ui. But I need to toggle this feature programmatically (using REST API or CLI) While browsing through the REST API documentation I didn't find a way to achieve this. Is there a way to get this done?

Analyzing the backend API call I found this, https://dev.azure.com/{organization_name}/{project_id}/_api/_versioncontrol/UpdateRepositoryOption?__v=5&repositoryId=00000000-0000-0000-0000-000000000000 But unable to send the request via postman or curl.

2 Answers

Well, this is not public API I think and even if you try to send you may not be able to overcome security checks. I tired and I got error message

The required anti-forgery cookie "__RequestVerificationToken" is not present. Ensure that cookies

enter image description here

You may create a feature request to make this avialble over REST API here. But, for the moment you are forced to do it manually.

Agree with Krzysztof Madej.

Test with the backend API to change the Repo Settings(New)/Options(Old), I get the same issue.

The required anti-forgery cookie "__RequestVerificationToken" is not present. Ensure that cookies are enabled in your browser.

This is a ticket with a similar problem.

The product group confirms that there is no workaround for this issue. It is indeed a security check.

When encountering this problem, it shows that this API cannot be called outside of a Azure Devops web page.

I am afraid that there is no API/CLI to achieve your requirement, you can only achieve it through the UI page for the time being.

Related