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


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


Related Posts

General Build Pipeline (CI) in Azure DevOps

Let’s walk through a general-purpose Azure DevOps build pipeline template that can be applied to most common application types (web apps, APIs, microservices, etc.) using CI/CD best…

Read More

Azure DevOps Interview Questions & Answers

Azure DevOps Interview Questions & Answers 1️⃣ Essential (Basic) Questions These test your foundation. 1. What is Azure DevOps?Azure DevOps is Microsoft’s cloud service providing DevOps tools…

Read More

Types of Merge Strategies or Commit Behaviors in Azure Devops

In Azure DevOps (and Git in general), when merging branches, there are several types of merge strategies or commit behaviors beyond just fast-forward. Here’s a breakdown: βœ……

Read More

Azure DevOps – Different Use Case (Part-6)

Artifacts in Azure DevOps can be used in various scenarios to facilitate different aspects of the CI/CD pipeline. Here are some additional use cases that demonstrate the…

Read More

Azure DevOps – Artifacts (Part-5)

Artifacts in Azure DevOps play a crucial role in the continuous integration and continuous delivery (CI/CD) process by storing and transferring the outputs of a build process….

Read More

Azure DevOps – Pipeline (Part-4)

In Azure DevOps, a pipeline is a workflow that defines how your code is built, tested, and deployed. Pipelines automate the process of continuous integration (CI) and…

Read More
guest
0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x
()
x