Home / Blog / Cleaning Up Git Branches in Azure DevOps
Cleaning Up Git Branches in Azure DevOps

Cleaning Up Git Branches in Azure DevOps

Cleaning up Git branches is needed from time to time to keep the workspace organised.

Using Azure DevOps most of the Git housekeeping tasks are automated. A typical default workflow follows these steps:
- From a sprint work item, a new remote (feature/bugfix) branch is created.
- Commit changes to the local branch.
- Push change to the remote repository.
- Create Pull Request to review the changes.
- Complete the Pull Request to merge the changes to the master branch.
- Delete the remote and local feature branch.

If automatic completion of a Pull Request is enabled the remote feature branch is deleted after a successful merge operation.

AzureDevOps automatic completion

Despite the default DevOps Git workflow some remote branches are not cleaned up. This is the case for a work item that is cancelled or not needed anymore. Or a Pull requested was completed without the automatic delete option enabled. From time to time visit the DevOps Branches page to review and clean up unneeded branches.

AzureDevOps all branches

Before deleting a branch, use the Compare branches option to review changes between master and the selected branch.

AzureDevOps delete branch

Deleting a branch can give the error message: “Failed to delete feature. Force push permission is required to delete branches”.

AzureDevOps delete branch warning

It is needed to adjust the default branch security.

AzureDevOps branch security

In the pop-up window enable the Force push option.

AzureDevOps force push option

Try again to delete the branch and it is gone.