How to remove unused (stale) branches in Git

I'm a software consultant who loves to build projects and share my learnings on this blog.
Search for a command to run...

I'm a software consultant who loves to build projects and share my learnings on this blog.
No comments yet. Be the first to comment.
Azure Functions is a powerful serverless compute platform, and Azure App Service handles a lot of the underlying configuration for you out of the box. However, there are scenarios where you may want t

If you’ve been exploring Azure AI learning paths or watching older demos, you’ve probably run into something confusing: The documentation and training links often reference Foundry (Classic) But the portal you’re using today might show Foundry (New...

In today's digital age, speed is paramount for web and mobile applications. Users expect instantaneous responses, and any delay can lead to a poor user experience and loss of engagement. Therefore, as developers, it's crucial to build web APIs that a...

Loops are fundamental constructs in any programming language. But have you ever wondered if there are any performance differences between them? For small collections, the difference might be negligible, but what about handling a million or 10 million...

When using an Azure Function app, it is necessary to connect it to a storage account, often referred to as Host storage. This storage is utilized by the Functions runtime, as well as by various triggers and bindings to coordinate between multiple run...

Many times while completing a pull request we delete the source branch, this deletes the branch from the git server, but still, the reference to that branch would appear in Visual Studio. Even if you do a fetch, pull or sync, the deleted branch from the server would still appear in Visual Studio.
![]() | ![]() |
As you can see in the above image, a deleted branch (feature1 branch) still shows up in visual studio.
So to remove, first let's check which branches have to be pruned (remove reference). Run
git remote prune origin --dry-run

The argument --dry-run just mimics the prune and does not actually remove it.
Now to remove the branches, run the prune command without the --dry-run argument.
git remote prune origin

If you go ahead and check in visual studio, you wouldn't find the pruned branches inside remote.

If you want to remove the local branch as well; right-click on that branch in visual studio and choose delete from the context menu.
Alternatively, you could also run
git branch -d feature1
in a terminal window.

That's it!! You have removed references to your unused local and remote branches!