Last active
October 24, 2022 18:44
-
-
Save adurbalo/b09225c3055ae3bbe5e99fa29419a81d to your computer and use it in GitHub Desktop.
Clean up old branches in repo
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
| echo `git fetch --prune origin` | |
| isRemoveEnabled=false | |
| while [ -n "$1" ] | |
| do | |
| case "$1" in | |
| --remove) | |
| isRemoveEnabled=true | |
| ;; | |
| -) shift | |
| break | |
| ;; | |
| *) echo "$1 unknown parameter, available options is [--remove]" | |
| exit 1 | |
| ;; | |
| esac | |
| shift | |
| done | |
| for branch in $(git branch -r | sed /\*/d); do | |
| if [ -z "$(git log -1 --since='90 days ago' -s $branch)" ]; then | |
| if [[ $branch != origin* ]]; then | |
| echo "⏭ Skipping non origin" | |
| continue | |
| fi | |
| if [[ $branch == origin/release/* ]]; then | |
| echo "⏭ Skipping: $branch" | |
| continue | |
| fi | |
| if [[ $branch == origin/maste* ]]; then | |
| echo "⏭ Skipping: $branch" | |
| continue | |
| fi | |
| if [[ $branch == origin/main* ]]; then | |
| echo "⏭ Skipping: $branch" | |
| continue | |
| fi | |
| if [[ $branch == origin/HEAD* ]]; then | |
| echo "⏭ Skipping: $branch" | |
| continue | |
| fi | |
| if [[ $branch == origin/develop* ]]; then | |
| echo "⏭ Skipping: $branch" | |
| continue | |
| fi | |
| echo `git show --format="%ci %cr %an" $branch | head -n 1` \\t$branch | |
| if $isRemoveEnabled ; then | |
| prefix="origin/" | |
| string="$branch" | |
| branchName=${string/#$prefix} | |
| echo "🗑 Removing..." | |
| git push --delete origin $branchName | |
| fi | |
| fi | |
| done |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
./repo_clean.shin repo root dir to print list of old branches./repo_clean.sh --removeto delete branches