Skip to content

Instantly share code, notes, and snippets.

@ktchernov
Created May 9, 2018 02:58
Show Gist options
  • Save ktchernov/f17812c2f42c3120c138a8e889256cf2 to your computer and use it in GitHub Desktop.
Save ktchernov/f17812c2f42c3120c138a8e889256cf2 to your computer and use it in GitHub Desktop.
Prune local branches
#!/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