Last active
September 17, 2018 07:07
-
-
Save hngl/16f00bc09e9398583fb3de271e81a54f to your computer and use it in GitHub Desktop.
git: Delete merged remote 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
# First checkout master! | |
# First remove local remote tracking branches that no longer exist on remote | |
git remote prune origin | |
# Now remove remote branches that are merged in the currect branch (except `master`, `demo` and `rc) | |
git branch -r --merged | | |
grep origin | | |
grep -v '>' | | |
grep -v master | | |
grep -v rc | | |
grep -v demo | | |
xargs -L1 | | |
cut -d"/" -f2- | | |
xargs git push origin --delete | |
# List remaining builds | |
for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format="%ai %ar by %an" $branch | head -n 1` \\t$branch; done | sort -r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment