Skip to content

Instantly share code, notes, and snippets.

@redthor
Last active September 15, 2020 12:49
Show Gist options
  • Select an option

  • Save redthor/3776c1f726cafff41c9eda6f271466c3 to your computer and use it in GitHub Desktop.

Select an option

Save redthor/3776c1f726cafff41c9eda6f271466c3 to your computer and use it in GitHub Desktop.

Revisions

  1. redthor revised this gist Apr 13, 2018. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions delete_branches_older_than.sh
    Original file line number Diff line number Diff line change
    @@ -26,5 +26,8 @@ if [[ ! -z $branches ]]; then
    else
    git branch -D $branches
    git push --delete origin $branches

    # clean up locally
    git remote prune origin
    fi
    fi
  2. redthor created this gist Apr 13, 2018.
    30 changes: 30 additions & 0 deletions delete_branches_older_than.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    # Copy of https://gist.github.com/antonio/4586456
    # With a modification to collect all the branch names so we can make one git request
    # Set DRY_RUN=1 to get an echo of the command

    # Format that works with `git log --since`, e.g. 2018-01-01
    date=$1

    branches=

    for branch in $(git branch -a | sed 's/^\s*//' | sed 's/^remotes\///' | grep -v 'master$'); do
    if [[ "$(git log $branch --since $date | wc -l)" -eq 0 ]]; then
    if [[ "$branch" =~ "origin/" ]]; then
    if [[ -z $branches ]]; then
    branches=$(echo "$branch" | sed 's/^origin\///')
    else
    branches="$branches "$(echo "$branch" | sed 's/^origin\///')
    fi
    fi
    fi
    done

    if [[ ! -z $branches ]]; then
    if [[ "$DRY_RUN" -eq 1 ]]; then
    echo git branch -D $branches
    echo git push --delete origin $branches
    else
    git branch -D $branches
    git push --delete origin $branches
    fi
    fi