Skip to content

Instantly share code, notes, and snippets.

@darrenclark
Last active September 2, 2016 15:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save darrenclark/efaaac743e4da819f7ec414f39b62a48 to your computer and use it in GitHub Desktop.
Git BRanchClean - Remove local branches that have been merged
#!/bin/bash
set -eu -o pipefail
## Git BRanchClean (removes local branches that have been merged into the current branch)
# List of branches to ignore separated by vertical bars/pipes (|)
IGNORED_BRANCHES="develop|master"
branches="$(git branch --no-column --no-color --merged | egrep -v '\* ' | sed 's/^[\* ] //' | (egrep -v "$IGNORED_BRANCHES" || true))"
if [[ -z "$branches" ]]; then
echo "No branches to delete"
exit
fi
echo "Following branches have been merged:"
for branch in $branches; do
echo "- $branch"
done
echo -n "Delete? [yN] "
read should_delete
if [[ "$should_delete" == "y" ]]; then
for branch in $branches; do
git branch -d "$branch"
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment