Skip to content

Instantly share code, notes, and snippets.

@inxilpro
Created November 6, 2024 21:08
Show Gist options
  • Save inxilpro/213ab8c0f424df5c60211bc59bc404d1 to your computer and use it in GitHub Desktop.
Save inxilpro/213ab8c0f424df5c60211bc59bc404d1 to your computer and use it in GitHub Desktop.
#!/bin/bash
now=$(date +%s)
two_years_in_seconds=$((2 * 365 * 24 * 60 * 60))
cutoff_date=$((now - two_years_in_seconds))
git for-each-ref --format '%(authordate:iso) %(refname)' refs/heads | while read line; do
authordate="${line%% refs/heads/*}"
authordate_unix=$(date -j -f "%Y-%m-%d %H:%M:%S %z" "$authordate" +%s)
refname="${line##* refs/heads/}"
if [ $cutoff_date -gt $authordate_unix ]; then
echo "git branch -D ${refname} # updated ${authordate}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment