I create a folder structure when creating branches, xavier/xxxx. I wanted to delete all those branches since they were old. I ended up doing it one by one, no matter what tool I used, and it was taking too long.
Here is a Powershell script that helped.
# Get all remote branches, filter for those starting with "xavier/"
$branches = git branch -r | Where-Object { $_ -match 'xavier/' } | ForEach-Object {
# Remove any leading/trailing whitespace and remove the "origin/" prefix
$_.Trim() -replace '^origin/', ''
}
# Loop through each branch and delete it from the remote repository
foreach ($branch in $branches) {
git push origin --delete $branch
}
Leave a Comment