Cleaning up old branches from VS Code
What's up everyone? So recently I was changing branches in VS Code and clicked the button to list my branches and... Bah. Tons and tons of old deleted branches. After quite a bit of googling I found that cleaning them up isn't that quick or simple. So I have written a quick PowerShell script to clean this up on windows for me. My primary language at my job day to day is PowerShell so that's why it's what I chose to write it in that. This will remove any local branches and clean up any branches that have been deleted in the git system of your choice on your local system. I unfortunately don't have any screenshots due to cleaning it up before thinking that I should take some to show this in action.
Code below:
A quick word of untested caution. Make sure all of your branches are pushed to your git repo system of choice before running this code.
Code below:
1 2 3 4 5 6 7 8 9 10 | $Branches = git branch foreach ($Branch in $Branches) { if ( $Branch -ne "* master") { $BranchName = $Branch.Replace(" ", "") Write-Host "Deleting Branch $BranchName" git branch -d $BranchName } } git fetch --prune |
A quick word of untested caution. Make sure all of your branches are pushed to your git repo system of choice before running this code.