Last active
July 22, 2019 09:41
-
-
Save douglasduteil/9fb0d8ea4eddf299b0c21e49ca4ef50e to your computer and use it in GitHub Desktop.
Delete branches on mirror remote
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
#!/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