How to create ADO REPO with 'develop' branch as default using ADO API calls

Viewed 95

I am using ADO API calls to create REPO and related governance for the branches using ADO APIs. Look my repo.yml having all API details. While repo is created; i get 'master' & 'develop' branches out of it. But master branch setting as the Default branch. I want to make Develop branch as default. How can I do that? what is the right API for that?

---
branches:
  -
    master:
      bypass: false
      content:
        - placeholder.txt
      policies:
        -
          merge:
            id: -3
            isBlocking: true
            isDeleted: false
            isEnabled: true
            settings:
              allowNoFastForward: true
              allowRebase: false
              allowRebaseMerge: true
              allowSquash: false
              scope:
                -
                  matchKind: Exact
                  refName: refs/heads/master
                  repositoryId: ~
              useSquashMerge: true
            type: ~
            url: ""
        -
          approval_count:
            id: -2
            isBlocking: true
            isDeleted: false
            isEnabled: true
            settings:
              allowDownvotes: false
              creatorVoteCounts: false
              minimumApproverCount: 1
              resetOnSourcePush: true
              scope:
                -
                  matchKind: Exact
                  refName: refs/heads/master
                  repositoryId: ~
            type: ~
            url: ""
        -
          build:
            id: -250
            isBlocking: true
            isDeleted: false
            isEnabled: true
            settings:
              buildDefinitionId: 1
              displayName: "Main Pipeline"
              manualQueueOnly: false
              queueOnSourceUpdateOnly: true
              scope:
                -
                  matchKind: Exact
                  refName: refs/heads/master
                  repositoryId: ~
              validDuration: 0
            type: ~
            url: ""
        -
          example:
            id: -4
            isBlocking: true
            isDeleted: false
            isEnabled: true
            settings:
              addedFilesOnly: false
              filenamePatterns: []
              ignoreIfSourceIsInScope: false
              message: ""
              requiredReviewerIds: 1
              scope:
                -
                  matchKind: Exact
                  refName: refs/heads/master
                  repositoryId: ~
            type: ~
            url: ""
  -
    develop:
      bypass: true
      content:
        - azure-pipelines.yml
        - placeholder.txt
        - params.json
        - .gitignore
      policies: []
organization_url: "https://xxxx.visualstudio.com/"
project: CloudTeam
1 Answers

I would consider a follow-up call to set the branch to develop, with

PATCH https://dev.azure.com/yourOrgName/yourProject/_apis/git/repositories/yourRepoId?api-version=6.0

and request body

{
  "defaultBranch": "refs/heads/develop"
}
Related