diff --git a/scripts/delete-remote-branches.sh b/scripts/delete-remote-branches.sh new file mode 100755 index 00000000..94775b1f --- /dev/null +++ b/scripts/delete-remote-branches.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# Delete all remote branches that don't have a local copy. + +remote="rad" + +# Iterate over all remote branches. +for branch in $(git branch -r --format "%(refname:short)"); do + # Extract the branch name without the "$remote/" prefix. + branch=${branch#"$remote/"} + # Never delete the master branch. + if [ "$branch" == "master" ]; then + continue + fi + + # Check if the branch doesn't exist locally. + if ! git rev-parse --quiet --verify "$branch" >/dev/null; then + git push -o "no-sync" $remote --delete "$branch" + echo "Deleted '$branch'" + fi +done + +rad sync --announce