Forked from AvnerCohen/delete_branches_older_than.sh
Last active
December 2, 2020 12:37
-
-
Save samueladesoga/ee31deb88b542878d633ff8585e0ff7f to your computer and use it in GitHub Desktop.
Script to delete branches older than 6 months old, ignore local vs remote errors.
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/sh | |
| ECHO='echo' | |
| for branch in $(git branch -a | sed 's/^\s*//' | sed 's/^remotes\///' | grep -Ev 'staging|develop|production|master$'); do | |
| if [[ "$(git log $branch --since "6 months ago" | wc -l)" -eq 0 ]]; then | |
| if [[ "$DRY_RUN" = "false" ]]; then | |
| ECHO="" | |
| fi | |
| local_branch_name=$(echo "$branch" | sed 's/remotes\/origin\///') | |
| $ECHO git branch -d $local_branch_name | |
| $ECHO git push origin --delete $local_branch_name | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment