Skip to content

Instantly share code, notes, and snippets.

@tandibar
Created February 22, 2012 09:56
Show Gist options
  • Save tandibar/1883721 to your computer and use it in GitHub Desktop.
Save tandibar/1883721 to your computer and use it in GitHub Desktop.
Check wheather a branch has differences with master or not
#!/usr/bin/env bash
for branch in $(git branch -a | grep "remotes/origin/" | grep -v "master" | sed 's|remotes/||')
do
echo "checking $branch for unmerged changes"
if git diff --exit-code master...$branch > /dev/null
then
echo "no commits found which were not already merged into master"
echo "should i delete the branch $branch?(y/n): "
read answer
if [ $answer = "y" ]
then
echo "deleting $branch"
git branch -d -r $branch
git push origin :`echo $branch | sed 's|origin/||'`
else
echo "not deleting $branch"
fi
else
echo "--> DIFFERENCES found, should not be deleted"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment