Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
remove old remote git branches interactively
#!/bin/sh
git fetch
for branch in `git branch --remote --merged origin/master | sed 's/ *origin\///' | grep -v ' ' | grep -v 'master$'`
do
MERGE_EPOCH=$(git --no-pager log -1 --pretty='%ct' $(git merge-base origin/master origin/$branch))
CURRENT_EPOCH=$(git --no-pager log -1 --pretty='%ct' origin/master)
if [ $(expr $(expr $CURRENT_EPOCH - $MERGE_EPOCH) / 60 / 60 / 24) -ge 14 ]; then
echo "$branch was merged $(git --no-pager log -1 --pretty='%ar' $(git merge-base origin/master origin/$branch))"
echo
git --no-pager log -3 --pretty='format: %Cblue%h%Creset (%Cgreen%ar%Creset) %an %s' --no-merges origin/$branch
echo
echo
/bin/echo -n "git push origin :$branch? [y/N] "
read reply
echo
if [ "$reply" == 'y' -o "$reply" == 'Y' ]; then
git push origin :$branch
echo
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.