Last active
October 26, 2016 06:09
-
-
Save 62mkv/a5930d2dd3e7ca81d641 to your computer and use it in GitHub Desktop.
Bash script to remove merged branches both locally and remotely (from "origin" only). Parses all REPOs within current folder, checkouts "master" on each of the REPOs
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
function remove_remote_branch() { | |
branch=$1 | |
git push origin --delete $branch | |
} | |
function remove_local_branch() { | |
branch=$1 | |
git branch -d $branch | |
} | |
PROTECTED="\(develop\|master\|qa\|sandbox\)" | |
for folder in `ls -1d */` ; do | |
cwd=`pwd` | |
git=${folder%/} | |
echo "--" | |
echo "Working with $git:" | |
cd $git | |
git checkout master | |
git pull origin | |
git remote prune origin | |
for branch in `git branch -r --merged origin/master | grep -vw $PROTECTED | grep -w "origin" | perl -e "while(<>) { s/origin\///g; s/ //g; print $_;}"` ; do | |
remove_remote_branch $branch | |
done | |
for branch in `git branch --merged origin/master | grep -vw $PROTECTED` ; do | |
remove_local_branch $branch | |
done | |
git remote prune origin | |
cd .. | |
done |
Added local branches purging
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Processes all the repos from the current folder!