Skip to content

Instantly share code, notes, and snippets.

View QuestGraves's full-sized avatar
🏠
Working from home

Matt Graves QuestGraves

🏠
Working from home
  • Ann Arbor, MI
View GitHub Profile
@njames
njames / delete_branches_older_than.sh
Last active July 18, 2024 02:22 — forked from AvnerCohen/delete_branches_older_than.sh
Script to delete branches older than 6 months old, ignore local vs remote errors.
#!/bin/sh
ECHO='echo '
for branch in $(git branch -a | sed 's/^\s*//' | sed 's/^remotes\///' | grep -v 'main$\|develop$'); do
if ! ( [[ -f "$branch" ]] || [[ -d "$branch" ]] ) && [[ "$(git log $branch --since "1 month ago" | wc -l)" -eq 0 ]]; then
if [[ "$DRY_RUN" = "false" ]]; then
ECHO=""
fi
local_branch_name=$(echo "$branch" | sed 's/remotes\/origin\///')
$ECHO git branch -d "${local_branch_name}"