Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

How do I delete a branch in GitHub Visual Studio?

Visual Studio 2017 provides you easy access to both. To delete a local branch, right click on it and select Delete from the context menu. To delete a remote branch listed under the remotes/origin, right click on the desired branch and select Delete Branch From Remote from the context menu that pops up on the screen.

Does git pull remove deleted branches?

This is because "git pull" does not remove remote tracking branches for branches deleted from remote repo.

Does GitHub keep deleted branches?

The branches will be restorable indefinitely, unless the repository cache is cleared. We don't clear repository caches automatically (we're in the version control business, so we don't delete data unless we absolutely have to.


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


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.


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

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


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


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.