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

Posted by


๐Ÿ” 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.


Leave a Reply

Your email address will not be published. Required fields are marked *

0
Would love your thoughts, please comment.x
()
x