Skip to content

Instantly share code, notes, and snippets.

@umardx
Last active January 24, 2022 11:08
Show Gist options
  • Save umardx/b95ab03662bf7c0b7799d5375af649ab to your computer and use it in GitHub Desktop.
Save umardx/b95ab03662bf7c0b7799d5375af649ab to your computer and use it in GitHub Desktop.
#!/bin/sh
ECHO='echo '
for branch in $(git branch -a | sed 's/^\s*//' | sed 's/^remotes\///' | grep -v 'master$\|main$\|develop$'); do
if ! ( [[ -f "$branch" ]] || [[ -d "$branch" ]] ) && [[ "$(git log $branch --since "3 month ago" | wc -l)" -eq 0 ]]; then
local_branch_name=$(echo "$branch" | sed 's/remotes\/origin\///')
$ECHO git branch -d "${local_branch_name}"
$ECHO git push origin --delete "${local_branch_name}"
fi
done
#!/bin/bash -x
SINCE="2020-09-30"
git branch -r --sort=committerdate | sed /\*/d | grep -v "origin/master" | while read BRANCH; do \
if [[ -z "$(git log -1 --date=local --since="${SINCE}" -s ${BRANCH})" ]]; then \
echo "Deleting vranch ${BRANCH#origin\/} that older than ${SINCE}.";\
git push origin --delete "${BRANCH#origin\/}";fi \
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment