Last active
September 21, 2021 22:40
-
-
Save shayan09/c32c32edda1d63a037bc42a8e46693a6 to your computer and use it in GitHub Desktop.
Delete old git branches locally and remote
This file contains 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
#!/bin/bash | |
ECHO='echo ' | |
for branch in $(git branch -a | sed 's/^\s*//' | sed 's/^remotes\///' | grep -v 'master\|develop\|main'); do | |
if ! ( [[ -f "$branch" ]] || [[ -d "$branch" ]] ) && [[ "$(git log $branch --since "3 months ago" | wc -l)" -eq 0 ]]; then | |
local_branch_name=${branch/'origin/'/''} | |
git branch -d "${local_branch_name}" | |
git push origin --delete "${local_branch_name}" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment