Skip to content

Instantly share code, notes, and snippets.

@MichaelAquilina
Last active March 23, 2018 11:20
Show Gist options
  • Save MichaelAquilina/9d4d56204e29c7fea399a2b681dcee3c to your computer and use it in GitHub Desktop.
Save MichaelAquilina/9d4d56204e29c7fea399a2b681dcee3c to your computer and use it in GitHub Desktop.
Automatically clean merged branches in a project
#!/usr/bin/env sh
delete_type="-d"
if [ "$1" = "-D" ];then   
delete_type="-D"
fi
current="$(git rev-parse --abbrev-ref HEAD)"
git branch --merged "$current"| grep -v "$current" | while read -r branch;
do   
git branch "$delete_type" "${branch}"
done
@MichaelAquilina
Copy link
Author

Save this as git-clean-branches somewhere in your $PATH

you can then clean your brances by simply running

git clean-branches

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