Skip to content

Instantly share code, notes, and snippets.

@Ghostbird
Last active September 9, 2022 13:59
Show Gist options
  • Save Ghostbird/f6db35c06973040d6ded585be2d3970f to your computer and use it in GitHub Desktop.
Save Ghostbird/f6db35c06973040d6ded585be2d3970f to your computer and use it in GitHub Desktop.
Script to delete merged branches
#/bin/bash
branches=$(git branch --merged | grep -Ev "^\*|develop|master|main")
if [ "$branches" ]
then
git branch -d $branches
else
echo "Nothing to delete"
fi
@Ghostbird
Copy link
Author

Ghostbird commented Sep 9, 2022

Save it in your PATH and you can call it as: git branch-delete-merged. It should automatically work with git completion if you have it set up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment