Skip to content

Instantly share code, notes, and snippets.

@dvdstelt
Last active March 6, 2025 14:14
Show Gist options
  • Save dvdstelt/ff5bcca7bd1018c860dc7b9947480160 to your computer and use it in GitHub Desktop.
Save dvdstelt/ff5bcca7bd1018c860dc7b9947480160 to your computer and use it in GitHub Desktop.
Delete remote repositories

These commands work in Powershell.

Remember to copy them from the raw view, as certain characters can get messed up in HTML view.

List remote branches that have been merged

git branch -r --merged origin/master | %{ $\_.Trim().substring(7) } | Where { $\_ -Notmatch 'master' } | %{ echo $\_ }

DELETE remote branches that have been merged

git branch -r --merged origin/master | %{ $\_.Trim().substring(7) } | Where { $\_ -Notmatch 'master' } | %{ git push -d origin $\_ }

List remote branches that are not "master" and not "rfc-poa"

git branch -r | %{ $\_.Trim().substring(7) } | Where { $\_ -Notmatch 'master' -And $_ -Notmatch 'rfc-poa' } | %{ echo $\_ }

DELETE remote branches that are not "master" and not "rfc-poa"

git branch -r | %{ $\_.Trim().substring(7) } | Where { $\_ -Notmatch 'master' -And $\_ -Notmatch 'rfc-poa' } | %{ git push -d origin $\_ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment