Skip to content

Instantly share code, notes, and snippets.

@geebru
Last active February 1, 2022 16:01
Show Gist options
  • Save geebru/16bfe13641fdabf8b6e094f6850a60a5 to your computer and use it in GitHub Desktop.
Save geebru/16bfe13641fdabf8b6e094f6850a60a5 to your computer and use it in GitHub Desktop.
A shell script to check for all merged branches (local/remote) older than 6 months and delete them.
#!/bin/sh
for branch in $(git branch -r --merged | sed 's/^\s*//' | sed 's/^remotes\///' | grep -v 'develop$\|develop-hybrid$\|master$\|IPM-\|4\.'); do
if [[ "$(git log $branch --since "4 months ago" | wc -l)" -eq 0 ]]; then
local_branch_name=$(echo "$branch" | sed 's/origin\///')
echo 'Deleting: ' $local_branch_name
#git push origin :$local_branch_name
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment