Skip to content

Instantly share code, notes, and snippets.

@fALKENdk
Created January 25, 2017 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fALKENdk/f058b72f2d91b3c23cf06d906d811348 to your computer and use it in GitHub Desktop.
Save fALKENdk/f058b72f2d91b3c23cf06d906d811348 to your computer and use it in GitHub Desktop.
#!/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