scripts: Add `delete-remote-branches` script

This is useful for cleaning up remote branches that are no longer used.
This commit is contained in:
Alexis Sellier 2023-05-24 10:37:58 +02:00
parent 4176d62e38
commit 4722b9b417
No known key found for this signature in database
1 changed files with 22 additions and 0 deletions

View File

@ -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