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

后端 未结 10 1526
無奈伤痛
無奈伤痛 2021-01-29 20:50

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. <

相关标签:
10条回答
  • 2021-01-29 20:56

    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:

    1. In VSCode View > Command Palette (cmd/ctrl + Shift + P)
    2. type Configure Task
    3. Select Create tasks.json file from template and a new file will be created under .vscode folder.
    4. Inside tasks array add this:

    { "label": "Git Prune", "type": "shell", "command": "git remote prune origin", "problemMatcher": [] }

    How to use it:

    1. Open Command Palette
    2. Type Run Task and select it
    3. Select Git Prune

    Reference:

    1. Git prune
    0 讨论(0)
  • 2021-01-29 20:57

    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):

    • list all the branches
    • remove the master branch from the list
    • delete the branches in the list
    0 讨论(0)
  • 2021-01-29 21:00

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

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

    0 讨论(0)
  • 2021-01-29 21:00

    The shorter command is:

    git fetch -p
    
    0 讨论(0)
  • 2021-01-29 21:04

    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

    0 讨论(0)
  • 2021-01-29 21:05

    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 run git 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.

    0 讨论(0)
提交回复
热议问题