🔁 How to Change the Default Branch from master to main in Azure Repos (Azure DevOps)

Changing the default branch from master to main is now a widely adopted best practice for inclusivity and modern development workflows. If you’re working with Azure DevOps Repos, this blog will guide you through renaming your master branch to main and updating all related settings seamlessly.


🧩 Why Rename master to main?

Before we get into the steps, let’s understand why many teams are making this shift:

  • 🔄 Modern Standards: GitHub, GitLab, and Azure DevOps now recommend main as the default branch name.
  • 🤝 Inclusivity: Moving away from legacy terminology improves tech culture.
  • 🧪 Tool Compatibility: Modern CI/CD tools default to main.

🔧 Step-by-Step: Rename and Set main as Default Branch

✅ Step 1: Rename master to main

You can do this either through the Azure DevOps UI or your local Git terminal.

🖥️ Option A: Rename via Azure DevOps UI

  1. Navigate to your Azure DevOps project.
  2. Go to Repos > Branches.
  3. Locate the master branch.
  4. Click the three dots (•••) beside it.
  5. Select Rename and change the name to main.

💻 Option B: Rename Using Git Command Line

# Rename the local branch
git branch -m master main

# Push the renamed branch
git push -u origin main

# Optionally delete the old branch from remote
git push origin --delete master

🧭 Step 2: Set main as the Default Branch

Once renamed, you’ll need to make main the default branch for your Azure Repo:

  1. In Azure DevOps, go to Repos > Branches.
  2. Click the three dots (•••) next to the main branch.
  3. Select Set as default branch.

🛡️ Step 3: Update Branch Policies

If you had any branch policies (e.g., PR reviews, build validations) applied to master, make sure to:

  • Go to Project Settings > Repositories > Branch Policies.
  • Reconfigure those same policies for the new main branch.

🔁 Step 4: Update Pipelines and Workflows

🧬 For YAML Pipelines:

Open your azure-pipelines.yml and update:

trigger:
  branches:
    include:
      - main

🏗️ For Classic Pipelines:

  1. Navigate to your pipeline in Azure DevOps.
  2. Open the Triggers tab.
  3. Change the default branch from master to main.

📝 Final Tips

  • 🧪 Test Everything: Run your pipelines and validate deployments after renaming.
  • 📁 Check Permissions: Make sure service accounts and developers have access to the main branch.
  • 🚀 Communicate: Notify your team about the branch name change to avoid confusion.

🎯 Conclusion

Renaming your default branch to main in Azure DevOps is a straightforward task that aligns your project with current industry standards. By following the above steps, you ensure a smooth transition without disrupting your CI/CD or collaboration workflows.


💡 Pro Tip: Always create a backup or tag your current state before performing major changes in your repository.


Category: 
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments