Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Delete branches on mirror remote
#!/usr/bin/env bash
set -eu -o pipefail
git fetch ${ORIGIN} -p
git fetch ${SUPER} -p
git branch -a | grep "remotes/${ORIGIN}" | grep -v HEAD > /tmp/origin
cat /tmp/origin
cat /tmp/origin | cut -d '/' -f 3- | sort > /tmp/origin_branches
cat /tmp/origin_branches
git branch -a | grep "remotes/${SUPER}" > /tmp/super
cat /tmp/super
cat /tmp/super | cut -d '/' -f 3- | sort > /tmp/super_branches
cat /tmp/super_branches
comm -31 /tmp/origin_branches /tmp/super_branches > /tmp/branches_to_remove
cat /tmp/branches_to_remove
echo "About to remove $(cat /tmp/branches_to_remove | wc -l) branches from ${SUPER}"
cat /tmp/branches_to_remove | xargs -I{} -n1 git push ${SUPER} :{}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment