Skip to content

Instantly share code, notes, and snippets.

@clauswitt
Created January 23, 2012 09:25
Show Gist options
  • Save clauswitt/1662029 to your computer and use it in GitHub Desktop.
Save clauswitt/1662029 to your computer and use it in GitHub Desktop.
Remove unused tracking branches
#!/bin/bash
TMPFILE=".tmpGitRemotes"
REMOTENAME="origin"
COMMIT=$1
git fetch
git branch -a --merged |grep "remotes/$REMOTENAME/" > $TMPFILE
if [[ $COMMIT == "commit" ]]; then
echo "deleting git branches"
else
echo "dry run - call with commit to delete branches"
fi
while read line; do
BRANCHNAME=`basename $line`
if [[ $BRANCHNAME -ne "master" ]]; then
if [[ $COMMIT == "commit" ]]; then
echo "running: git push $REMOTENAME :$BRANCHNAME"
git push $REMOTENAME :$BRANCHNAME
else
echo "git push $REMOTENAME :$BRANCHNAME"
fi
fi
done<$TMPFILE
rm $TMPFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment