Skip to content

Instantly share code, notes, and snippets.

@mdzhang
Created January 24, 2024 21:22
Show Gist options
  • Save mdzhang/5f31f57e91b466cb5b7eab921851dd75 to your computer and use it in GitHub Desktop.
Save mdzhang/5f31f57e91b466cb5b7eab921851dd75 to your computer and use it in GitHub Desktop.
delete old git branches
#!/bin/bash
git fetch --prune
for k in $(git branch -r --sort=committerdate | head -n 100); do
if [ -z "$(git log -1 --after='2 years ago' -s $k)" ]; then
br=$(echo $k | cut -d'/' -f2-)
echo "Removing $br"
echo "--"
echo "Summary:"
git log -n 1 --pretty=format:"%h %an, %ar : %s" $k
echo "--"
git push origin -d $br
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment