Skip to content

Instantly share code, notes, and snippets.

View e-sung's full-sized avatar

류성두 e-sung

View GitHub Profile
@e-sung
e-sung / delete_branches_older_than.sh
Last active March 2, 2022 05:44 — forked from njames/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 -wv 'main\|develop\|master\|release'); do
if ! ( [[ -f "$branch" ]] || [[ -d "$branch" ]] ) && [[ "$(git log $branch --since "3 month ago" | wc -l)" -eq 0 ]]; then
if [[ "$DRY_RUN" = "false" ]]; then
ECHO=""
fi
local_branch_name=$(echo "$branch" | sed 's/remotes\/origin\///')
echo "Deleting: " + $local_branch_name