Set Default Branch in Azure Repos

Reference


Quite often master branch is not your default branch for your team’s pull requests. No matter how much you want it to be. Often, teams are using develop branch as a sort of a buffer/integration branch to give them extra flexibility before committing to master. If you want to change a default branch for your repo, you can follow the following steps one repo at a time:

Or, you can use az devops cli commands to change default branch for all of your repos:

TOKEN=ENTER_YOUR_TOKEN_HEREORGANIZATION=ENTER_YOUR_ORGANIZATION_HEREPROJECT=ENTER_YOUR_PROJECT_HEREDEFAULT_BRANCH=ENTER_YOUR_NEW_DEFAULT_BRANCH_HERE
#define REST API URL to get all Azure Repos
repos_URL="https://dev.azure.com/$ORGANIZATION/$PROJECT/_apis/git/repositories?api-version=4.1"

#get all Azure Repos IDs
repo_ids=$(curl -s -X GET -u PAT:$TOKEN $repos_URL | jq -r '.value[].id')

#authenticate to Azure DevOps CLI
$env:AZURE_DEVOPS_EXT_PAT=$TOKEN
az devops login --organization https://dev.azure.com/$ORGANIZATION

#walk through all repos in the team project and assign new default branch
for repo_id in $repo_ids; do
echo "setting default branch for $repo_id repo to $DEFAULT_BRANCH"az repos update --org "$ORG_URL" --project "$PROJECT" --repository $repo_id --default-branch $DEFAULT_BRANCHdone

Hope this helps.

Commentaires

Posts les plus consultés de ce blog

Petite réflexions sur l'Intelligence Artificielle (IA) en 2025

Chère daddy Noël ... Plein de bon voeux à toi

ByteRoots Studio is open!