Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to delete branches older than 6 months old, ignore local vs remote errors.
#!/bin/sh
ECHO='echo '
for branch in $(git branch -a | sed 's/^\s*//' | sed 's/^remotes\///' | grep -v '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
@njames
Copy link

njames commented Jun 15, 2021

my full script is here ... note I want to exclude main and develop

https://gist.github.com/njames/88425c2771a14c5fe1220c19a16bdac6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment