Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
delete merged branches in git, if you want to.
local current_branch=$(git rev-parse --abbrev-ref HEAD)
for branch in $(git branch --merged | cut -c3-)
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
Copy link

krone commented Aug 27, 2014

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

Copy link

unyo 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