Created
July 4, 2012 14:49
-
-
Save cokron/3047733 to your computer and use it in GitHub Desktop.
delete merged git branches
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
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') | |
echo $current_branch | |
echo "finding branches that have already been merged into $current_branch" | |
for branch in $(git branch -a | grep "remotes/origin/" | grep -v "$current_branch" | grep -v "develop" | grep -v "master" | grep -v "origin/HEAD" | sed 's|remotes/||') | |
do | |
echo "checking $branch for unmerged changes" | |
if git diff --exit-code $current_branch...$branch > /dev/null | |
then | |
echo "no commits found which were not already merged into $current_branch" | |
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 | |
echo "" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment