Last active
March 22, 2023 22:23
-
-
Save johnkors/2c79a11c6372a84bf3237954968594f1 to your computer and use it in GitHub Desktop.
PowerShell script to delete branches merged to master
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# update local list of pruned branches on the remote to local: | |
git fetch --prune | |
# delete branches on remote origin that have been merge to master | |
git branch --merged remotes/origin/master -r | %{$_.trim().replace('origin/', '')} | ?{$_ -notmatch 'master'} | %{git push --delete origin $_} | |
# delete local branches that have been merged to master | |
git branch --merged remotes/origin/master | %{$_.trim()} | ?{$_ -notmatch 'master'} | %{git branch -d $_} | |
# remove stale refs (local refs to branches that are gone on the remote) | |
git remote prune origin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Comments in powershell are with the "#" symbol, not with "//".
Other than that, thanks for the script! Works like a charm.