Last active
February 14, 2017 18:19
-
-
Save atarola/8ce94d480b9ce23fd8b4 to your computer and use it in GitHub Desktop.
Cleanup a Repo
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 | |
# | |
# Cleanup both local and remote branches that have been merged to master | |
# | |
PREFIX="remotes/origin/" | |
# make sure you're on master | |
git checkout master | |
git pull | |
# clean the local git | |
git remote prune origin | |
for branch in $(git branch -a --merged | grep -v "*"); do | |
if [[ $branch == *master* || $branch == *HEAD* || $branch == "->" ]]; then | |
# don't delete master | |
echo " - skipping: $branch" | |
continue | |
fi | |
if [[ $branch == *origin* ]]; then | |
echo " - remote branch: $branch" | |
remote=${branch#$PREFIX} | |
git push origin :$remote | |
else | |
echo " - local branch: $branch" | |
git branch -d $branch | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment