In VSCode, after I do a pull request and delete the branch on GitHub, that branch still shows up in Visual Studio Code. If I select the branch, it gives an Error, as expected. <
All you need to do is to run this command:
git remote prune origin
Something extra that you can do, because it's annoying sometimes to open a terminal just for that.. you can add a task in vscode.
To do that please make follow these steps:
{ "label": "Git Prune", "type": "shell", "command": "git remote prune origin", "problemMatcher": [] }
How to use it:
Reference:
You can remove all the local branches (except master) with:
git branch -r | grep -v "master" | xargs git branch -D
And you can remove all the branches still appearing as origin/XXXX
in VSCode but already deleted in origin
with:
git fetch --prune
Note:
The first command above (taken from https://stackoverflow.com/a/52006270/3120163):
Open the command palette (Ctrl+Shift+P) and select Git: Fetch (Prune).
This feature was merged into VS Code on Nov 20, 2018.
The shorter command is:
git fetch -p
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
You don't have to git fetch --prune
and restart VSCode anymore.
With VSCode 1.52 (Nov. 2020), you now have:
Git: Prune on fetch
Enabling the
git.pruneOnFetch
setting will make VS Code rungit fetch --prune
when fetching remote refs.
No more extra branch locally once they have been deleted from GitHub.
See PR 89249, fixing issue 86813:
Usage:
{ "git.pruneOnFetch": true }
Setting is
false
by default.This would add the
--prune
flag to all git fetches.