# How to remove unused (stale) branches in Git

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.

| ![server-branches1-1.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1613281790739/ae2U1ICfm.png) | ![visual-studio-branch-status-1.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1613281803867/o5w8vifnE.png) |
| --- | --- |

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

```bash
git remote prune origin --dry-run
```

![prune-dry-run1-1.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1613281856830/tsnRWFJ8q.png)

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.

```bash
git remote prune origin
```

![git-prune-1.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1613281915391/09pSfgk7d.png)

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

![post-pruning-visual-studio-1.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1613281968109/ELraY__tr.png)

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

```bash
git branch -d feature1
```

in a terminal window.

![delete-local-branch-1.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1613282015262/J6UaRKMTc.png)

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