Visual Studio Code - remove branches deleted on GitHub that still show in VS Code?

Solution 1:

Apparently, this feature is intentional. I found out that a correct way to remove all remote branches that have been deleted from Github is to run the following command.

git fetch --prune

Then restart visual studio to remove the branches from the command palette

Solution 2:

Local branches can be removed from Visual Studio Code by opening the Command Pallete (Ctrl-Shift-P) then Selecting Git: Delete Branch..., you can then delete the local branch by selecting the appropriate one from the list.

Solution 3:

Open the command palette (Ctrl+Shift+P) and select Git: Fetch (Prune).

This feature was merged into VS Code on Nov 20, 2018.

Solution 4:

Branches removed from GitHub are well... just removed from GitHub. You still have local copy of branch on your machine. To delete local branch run git branch -d the_local_branch. There is no command in VS Code to do so, but you can start terminal in VSCode using View: Toggle Integrated Terminal command and run command from it.

For more information about branch management please visit git documentation - https://git-scm.com/book/be/v2/Git-Branching-Branch-Management

Solution 5:

I interpreted the question to be: how can I delete my local branches that have been merged, since I've been using Git Fetch (Prune) from the command palette. This may be considered a "hack", but it's what I use. In the PowerShell terminal:

$branches = (git branch --merged).replace(" ", "").replace("*", "") | ? { $_ -ne "develop" -and $_ -ne "master" }
foreach ($branch in $branches) { git branch $branch -d }

In case you're not familiar with PoSH, here's what that does: the first line gets the name of all merged branches (with the exception of develop and master), and the second line loops through that list and runs "git branch -d". As long as the branch is merged completely, you should see:

Deleted branch <branch name> (was <commit ID>).

for each branch. Occasionally I'll run into a branch that fails to be deleted - if this happens, and you're sure that it's safe to be deleted (i.e. you won't lose local work that hasn't been stored), you can run:

git branch <branch name> -D

Note the capital D - that forcibly deletes the local branch.