-
-
Save jsanders/2968558 to your computer and use it in GitHub Desktop.
Find and remove old git branches
This file contains hidden or 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
| #!/bin/bash | |
| set -e | |
| branch=remotes/$1 | |
| function reverted_commits () { | |
| git log | grep 'This reverts commit' | awk '{ print substr($4, 1, 7) }' | tr -d '.,' | |
| } | |
| function branches () { | |
| git branch -av | grep "$1" | sed -e "s|$1/||" | awk '{ print $2 " " $1 }' | |
| } | |
| branches "$branch" | sort > branches.tmp | |
| reverted_commits | sort > reverts.tmp | |
| # Remove branches that have been reverted | |
| join -v1 branches.tmp reverts.tmp > candidates.tmp | |
| git log --format='%h' "$branch"/master | sort | join candidates.tmp - | |
| rm branches.tmp reverts.tmp candidates.tmp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment