Created
January 21, 2013 14:58
-
-
Save antonio/4586646 to your computer and use it in GitHub Desktop.
Delete branches that were rebased (reference never updated) and merged into master
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 | |
for branch in $(git branch -a | sed 's/^\s*//' | sed 's/^remotes\///' | grep -v 'master$'); do | |
last_commit_msg="$(git log --oneline --format=%f -1 $branch)" | |
if [[ "$(git log --oneline --format=%f | grep $last_commit_msg | wc -l)" -eq 1 ]]; then | |
if [[ "$branch" =~ "origin/" ]]; then | |
local_branch_name=$(echo "$branch" | sed 's/^origin\///') | |
if [[ -n "$EXEC" ]]; then | |
git push origin :$local_branch_name | |
else | |
echo "git push origin :$local_branch_name" | |
fi | |
else | |
if [[ -n "$EXEC" ]]; then | |
git branch -D $branch | |
else | |
echo "git branch -D $branch" | |
fi | |
fi | |
fi | |
done |
Seeing that there is a git push
in here, this probably does more than just deleting local branches.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
shared from https://stackoverflow.com/a/24801581