Skip to content

Instantly share code, notes, and snippets.

@douglasduteil
Last active July 22, 2019 09:41
Show Gist options
  • Save douglasduteil/9fb0d8ea4eddf299b0c21e49ca4ef50e to your computer and use it in GitHub Desktop.
Save douglasduteil/9fb0d8ea4eddf299b0c21e49ca4ef50e to your computer and use it in GitHub Desktop.
Delete branches on mirror remote
#!/usr/bin/env bash
set -eu -o pipefail
#
ORIGIN=${1:="origin"}
SUPER=${2:="super"}
#
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