Git BRanchClean - Remove local branches that have been merged
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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