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

后端 未结 10 1502
無奈伤痛
無奈伤痛 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 21:14

    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.

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

    I found a way to fix this. So you need to remove the remote that links to the Github repo, then add the remote again.

    All the branches that are deleted from Github will no longer show up in vscode. Assuming that origin is the name for the remote repo.

    git remote remove origin
    

    Then

    git remote add origin git@github.com:your-username/repo-name.git
    
    0 讨论(0)
  • 2021-01-29 21:18

    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

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

    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.

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