-
-
Save Prounckk/7e998354adebf85876e104fa04e358e6 to your computer and use it in GitHub Desktop.
Script to delete branches older than a certain date
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 | |
date=$1 | |
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 | |
local_branch_name=$(echo "$branch" | sed 's/^origin\///') | |
if [[ "$DRY_RUN" -eq 1 ]]; then | |
echo "git push origin :$local_branch_name" | |
else | |
git push origin :$local_branch_name | |
fi | |
else | |
if [[ "$DRY_RUN" -eq 1 ]]; then | |
echo "git branch -D $branch" | |
else | |
git branch -D $branch | |
fi | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment