Skip to content

Instantly share code, notes, and snippets.

@antonio
Created January 21, 2013 14:58
Show Gist options
  • Save antonio/4586646 to your computer and use it in GitHub Desktop.
Save antonio/4586646 to your computer and use it in GitHub Desktop.
Delete branches that were rebased (reference never updated) and merged into master
#!/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
@BoxResin
Copy link

@nicknijenhuis
Copy link

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