Skip to content

Instantly share code, notes, and snippets.

@motemen
Created December 29, 2011 07:48
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save motemen/1532754 to your computer and use it in GitHub Desktop.
Save motemen/1532754 to your computer and use it in GitHub Desktop.
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