Skip to content

Instantly share code, notes, and snippets.

@earlonrails
Last active November 22, 2021 21:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save earlonrails/6994990 to your computer and use it in GitHub Desktop.
Save earlonrails/6994990 to your computer and use it in GitHub Desktop.
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
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.

@unyo
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