Created
January 25, 2017 13:14
-
-
Save fALKENdk/f058b72f2d91b3c23cf06d906d811348 to your computer and use it in GitHub Desktop.
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 | |
branches_to_die=$(git branch --no-color --merged origin/master | grep -v '\smaster$') | |
echo "Local branches to be deleted:" | |
echo "$branches_to_die" | |
kill_branches () { | |
echo $branches_to_die | xargs -n 1 git branch -d | |
} | |
remote_branches_to_die=$(git branch --no-color --remote --merged origin/master | grep -v '\smaster$' | grep -v '\/master$' | grep -v "origin\/HEAD" | grep -v "origin\/master") | |
echo "Remote branches to be deleted:" | |
echo "$remote_branches_to_die" | |
kill_remote_branches () { | |
# Remove remote branches | |
for remote in $remote_branches_to_die | |
do | |
# branches=`echo "$remote_branches" | grep "$remote/" | sed 's/\(.*\)\/\(.*\)/:\2 /g' | tr -d '\n'` | |
git branch -rd "$remote" | |
done | |
} | |
echo "" | |
echo "Enter Y to confirm" | |
read -p "> " confirm | |
[[ $confirm == "Y" ]] && kill_branches && kill_remote_branches | |
echo "" | |
echo "Pruning all remotes" | |
git remote | xargs -n 1 git remote prune |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment