Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
delete merged branches in git, if you want to.
merged_branches(){
local current_branch=$(git rev-parse --abbrev-ref HEAD)
for branch in $(git branch --merged | cut -c3-)
do
echo "Branch $branch is already merged into $current_branch."
echo "Would you like to delete it? [Y]es/[N]o "
read REPLY
if [[ $REPLY =~ ^[Yy] ]]; then
git branch -d $branch
fi
done
}
@krone

This comment has been minimized.

Copy link

commented Aug 27, 2014

isn't line 9 just removing the local branch? Or is this script only to remove local branches.

@unyo

This comment has been minimized.

Copy link

commented Jul 22, 2015

@krone it looks like it's only for deleting local branches. if you want to delete from remote as well, theoretically adding "git push origin :$branch" after line 9 should work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.