Skip to content

Instantly share code, notes, and snippets.

@hngl
Last active September 17, 2018 07:07
Show Gist options
  • Save hngl/16f00bc09e9398583fb3de271e81a54f to your computer and use it in GitHub Desktop.
Save hngl/16f00bc09e9398583fb3de271e81a54f to your computer and use it in GitHub Desktop.
git: Delete merged remote branches
# 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