Created
November 12, 2012 23:11
-
-
Save gregoryjscott/4062692 to your computer and use it in GitHub Desktop.
delete merged 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
# define the branches to ignore | |
ignoredBranches="master\|staging\|production\|HEAD" | |
# run from master | |
git checkout master | |
# update list of remotes | |
git fetch | |
git remote prune origin | |
# remove local fully merged branches | |
git branch --merged master | | |
grep -v ${ignoredBranches} | | |
xargs git branch -d | |
# show remote fully merged branches | |
echo "The following remote branches are fully merged and will be removed:" | |
git branch -r --merged master | | |
sed 's/ *origin\///' | | |
grep -v ${ignoredBranches} | |
read -p "Continue (y/n)? " | |
if [ "$REPLY" == "y" ] | |
then | |
# remove remote fully merged branches | |
git branch -r --merged master | | |
sed 's/ *origin\///' | | |
grep -v ${ignoredBranches} | | |
xargs -i% git push origin :heads/% | |
echo "Done!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The -i option passed to xargs (line 29) needs to be lowercase in Git Bash on Windows (uppercase I throws error), but needs to be uppercase in Bash on OS X (lowercase i throws error).