Last active
July 31, 2025 08:23
-
-
Save jethroo/779a591d5da90229c66b to your computer and use it in GitHub Desktop.
deletes all local branches with no changes in 1 week
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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