Created
December 29, 2011 07:48
-
-
Save motemen/1532754 to your computer and use it in GitHub Desktop.
remove old remote git branches interactively
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
#!/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 "[33m$branch[00m 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