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

后端 未结 10 1529
無奈伤痛
無奈伤痛 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  (was ).
    

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

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

提交回复
热议问题