Skip to content

Instantly share code, notes, and snippets.

@jethroo
Last active July 31, 2025 08:23
Show Gist options
  • Select an option

  • Save jethroo/779a591d5da90229c66b to your computer and use it in GitHub Desktop.

Select an option

Save jethroo/779a591d5da90229c66b to your computer and use it in GitHub Desktop.
deletes all local branches with no changes in 1 week
for k in $(git branch | sed '/\*/d' | grep '..'); do
# Trim whitespace
k=$(echo $k | xargs)
echo "inspecting $k"
# Skip protected branches
if [[ "$k" == "master" || "$k" == "main" || "$k" == "staging" ]]; then
echo "skipping protected branch $k"
continue
fi
if [ -n "$(git log -1 --since='1 week ago' -s $k)" ]; then
echo "keeping $k"
else
echo "deleting $k"
git branch -D "$k"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment