Created
May 9, 2018 02:58
-
-
Save ktchernov/f17812c2f42c3120c138a8e889256cf2 to your computer and use it in GitHub Desktop.
Prune local branches
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 -ex | |
branch_name=$(git symbolic-ref -q HEAD) | |
branch_name=${branch_name##refs/heads/} | |
branch_name=${branch_name:-HEAD} | |
if [[ $branch_name = "HEAD" ]]; then | |
echo "Cannot work with a detached head" | |
exit 1 | |
fi | |
git stash | |
git checkout master | |
git branch --merged | grep -v master | sed 's/origin\///' | xargs -n 1 echo | |
git branch --merged | grep -v master | sed 's/origin\///' | xargs -n 1 git branch -d | |
git checkout $branch_name | |
#git stash pop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment