Last active
August 13, 2018 14:50
-
-
Save mbarcia/db8735ba8dc526323ca66773ec3c770a to your computer and use it in GitHub Desktop.
Cleanup of branches already merged
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
# Git clone the repository | |
git clone [email protected]:mbarcia/drupsible-project.git | |
cd drupsible-project/ | |
# Track all remote branches in the local repository | |
git branch -a | grep -v HEAD | perl -ne 'chomp($_); s|^\*?\s*||; if (m|(.+)/(.+)| && not $d{$2}) {print qq(git branch --track $2 $1/$2\n)} else {$d{$_}=1}' | csh -xfs | |
# Delete those branches already merged into master (in the remote repository) | |
git branch --merged | grep -v "master" | grep -v "*" | grep -v "\." | xargs -I % git push --delete origin % | |
# Delete those branches already merged into master (in the local repository) | |
git branch --merged | grep -v "master" | grep -v "*" | grep -v "\." | xargs -I % git branch -d % | |
# Prune remote origin | |
git remote prune origin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment