How to Delete a Branch in Azure DevOps

Deleting a branch in Azure DevOps isn’t just about simply deleting; it’s about maintaining and preserving workflow. Whether you are a GUI loyalist or a person who likes the Command Line, I’m going to walk you through exactly how to delete branches in Azure DevOps, ensuring you do it safely and effectively.

How to Delete a Branch in Azure DevOps

Why You Can’t Just Hit “Delete” (Sometimes)

Before we jump into the “how,” we need to address the “why not.” If you have tried to delete a branch and failed, it is usually due to one of two gatekeepers: Permissions or Policies.

  • Permissions: To delete a remote branch, you generally need “Force push” or specific “Delete” permissions on that repository. If you are a standard “Contributor,” you can usually delete branches you created, but you might be blocked from deleting others.
  • Branch Policies: You cannot delete the Default branch (usually main or master). Azure DevOps simply won’t let you until you change the default setting to another branch.

Check out: How To Recover Deleted Branch In Azure DevOps

Method 1: The Web Portal (The Easiest Way)

This is the method I use 90% of the time. It is visual, safe, and gives you a second to think before you commit to the deletion.

  1. Navigate to Repos: Log in to your Azure DevOps organization and open your project.
  2. Go to Branches: On the left-hand sidebar, hover over Repos and click Branches.
  3. Locate Your Branch: You will see tabs for “Mine” (branches you created) and “All”. If your branch is old, you might need to use the search bar at the top right.
  4. The “More actions” menu: Hover over the row of the branch you want to remove. You will see a more actions (three dots) menu appear on the far right.
  5. Confirm: Click the delete branch option. Azure DevOps might ask for confirmation. Once you click delete, the branch is removed from the remote repository immediately.

Check out the screenshots below for the complete steps:

How to Delete a Branch in Azure DevOps

Pro Tip: If you don’t see the trash can, click the three dots (…) next to the branch name. “Delete branch” will be an option in the dropdown menu.

Method 2: Visual Studio 2022

If you are working in a .NET shop, you likely live inside Visual Studio. You don’t need to leave your IDE to clean up your remote branches.

  1. Open the Git Menu: In the top menu bar, click Git.
  2. Manage Branches: Select Manage Branches from the dropdown. This opens a dedicated window that is far superior to the old Team Explorer view.
  3. Find the Remote Branch: In the sidebar, look under the remotes/origin folder.
    • Note: Deleting a branch under local only removes it from your machine. To actually delete it from Azure DevOps, you must target the remote branch.
  4. Right-Click and Delete: Right-click the branch name and select Delete.
  5. Confirm the Push: Visual Studio allows you to delete the remote branch directly. It basically sends a command to the server to strip that reference.

Check out the below screenshot for reference:

how to delete branch in azure devops

Method 3: The Command Line (The Power User Way)

For those of us who prefer the terminal, deleting a branch is a two-step process. You often have a local copy on your laptop and the remote copy on the Azure DevOps server. You usually want to kill both.

Step 1: Delete the Local Branch

First, ensure you are not currently checked out to the branch you want to delete. Switch to main first.

Bash

git checkout main
git branch -d feature/old-login-page
  • git branch -d is the safe delete. It will warn you if you have unmerged changes.
  • git branch -D (capital D) is the force delete. It destroys the branch even if work hasn’t been saved. Use with caution.