This guide describes how to delete a branch using the Visual Studio Code (VSC) editor and AzDevOps.
Note: Take care when deleting a branch, and only delete a branch if you’re sure that you need to.
The options for deleting a branch described in this guide only work on branches that have been pushed to, and merged with, AzDevOps already. Forcing the deletion of unmerged branches is beyond the scope of this guide.
Information about the Git
delete branch
command is available from the Software Freedom Conservancy’s Git branch documentation.
Prerequisites
Before you proceed complete the following:
- Install Visual Studio Code
- Install Docs Authoring Pack
- Install Word Count extension
- Install Pull Requests extension
- Install Azure Repos extension
- Install Git client
- Set Git credentials
- Terminology and concepts
- General project workflow
- Download course files (clone repo)
- Project branching policies
- Create new branch in VSC
- Send (push) files
Topics in this guide
Delete a branch using VSC
Complete the following steps to delete a branch using VSC.
Note: To complete this guide you must know how to switch branches, as described in the guide Switch branches.
-
Open VSC, and choose File > Open folder from the top menu.
-
Use the VSC open folder explorer to select the local repository folder (repo) on your computer, and then choose Select folder.
-
From the VSC top menu, choose Terminal > New Terminal.
Note: The VSC status bar, at the bottom of the editor window, indicates the name of the branch that VSC is currently switched to. For example, in the previous image, the VSC status bar indicates that VSC is currently switched to the branch named master.
You can’t delete the branch that VSC (or Git) is currently switched to. Switch to a branch other than the branch you want to delete, and then continue following this guide.
-
In the VSC Terminal, type the following command to delete the branch from your local repo, and then press Enter.
For example, in the following image, the local branch old-branch will be deleted. Replace branch_name with the name of the local branch you want to delete.
git branch --delete <branch_name>
A message in the VSC Terminal confirms that the branch is deleted from your local repo.
-
Delete the branch from AzDevOps with the
git push
command by typing the following command into the VSC Terminal, and then press Enter.git push origin --delete <branch_name>
For example, in the following image, the AzDevOps branch old-branch will be deleted from AzDevOps. Replace branch_name with the name of the AzDevOps branch you want to delete.
A message in the VSC Terminal confirms that the branch is deleted from AzDevOps.
You’ve deleted a branch using VSC successfully.
Delete a branch using AzDevOps
Complete the following steps to delete a branch using AzDevOps.
Note: Deleting a branch using AzDevOps removes the branch from AzDevOps only. Your local repo might retain a copy of the branch until you pull updates from AzDevOps into your local repo, or clone the AzDevOps repo again. To delete a branch from your local repo and from AzDevOps, follow the steps in Delete a branch using VSC.
-
Open a web browser, go to the AzDevOps website at https://dev.azure.com, and sign in.
-
On the Projects tab, locate the project repo with the branch you want to delete, and select the Repos icon.
For example, in the following image, the Repos icon for the project example-repo is selected.
-
Select Branches from the left side menu.
-
Select the vertical ellipsis (
⋮
) icon beside the branch you want delete (on the right side), and then choose Delete branch.For example, in the following image, the branch named old-branch will be deleted.
If you’re prompted to confirm the deletion, select Delete.
-
The message You updated <deleted-branch> just now indicates that the branch has been deleted from AzDevOps.
For example, in the following image, the message You updated old-branch just now indicates that the branch named old-branch is deleted from AzDevOps.
You’ve deleted a branch using AzDevOps successfully.
Appendices
Check the following supplementary Appendices for more details and context.