This will take a while to do.
-
Make a new clone of your repo.
git clone -bak cd -bak
-
Make a backup of all branches locally in case you fuck up something.
git branch -r | grep -v '->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done git fetch --all git pull --all # via https://stackoverflow.com/questions/10312521/how-to-fetch-all-git-branches#10312587
-
List all remote branches, oldest first
git for-each-ref --sort=committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)'
-
Add this to your
.(zsh|bash)rcgit-is-merged() { merge_destination_branch=$1 merge_source_branch=$2
merge_base=$(git merge-base $merge_destination_branch $merge_source_branch) merge_source_current_commit=$(git rev-parse $merge_source_branch) if [[ $merge_base == $merge_source_current_commit ]]; then echo $merge_source_branch fi}
git-list-merged() { git for-each-ref --sort=committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)' > /tmp/zsh-git-refs-temp while read line; do git-is-merged HEAD $(echo $line | awk -F" " '{print $2}') #echo $line done < /tmp/zsh-git-refs-temp rm /tmp/zsh-git-refs-temp }
git-rm-merged() { git-list-merged | egrep --invert-match '(master|sprint)' > /tmp/zsh-git-refs-merged-HEAD while read line; do echo git push origin --delete $line done < /tmp/zsh-git-refs-merged-HEAD rm /tmp/zsh-git-refs-merged-HEAD }
Run git-rm-merged (it's non-destructive, it will echo out what it would do). Adjust the egrep to your liking to exclude branches that you want to leave in.
Remember to source the changed .zshrc with . ~/.zshrc after doing changes.