Created
April 12, 2017 08:13
-
-
Save imran-baig-se/d0546e42d9bd85a964a3d9cbcaa85922 to your computer and use it in GitHub Desktop.
Clean git branches by specifying months
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
#!/usr/bin/env bash | |
# fetch all branches: | |
for k in $(git branch -a | sed /\*/d); do | |
# check if there is no changes since 3 month | |
if [ -z "$(git log -1 --since='3 month ago' -s $k)" ]; then | |
# prepare branch name | |
branch_name_with_no_origin=$(echo $k | sed -e "s/origin\///" | sed -e "s/remotes\///" ) | |
echo deleting branch: $branch_name_with_no_origin | |
# keep master | develop branch even if they are outdated. | |
if [ "$branch_name_with_no_origin" = "master" ] || [ "$branch_name_with_no_origin" = "develop" ]; then | |
echo "skip $branch_name_with_no_origin" | |
else | |
echo "deleting branch $branch_name_with_no_origin" | |
git push origin --delete $branch_name_with_no_origin | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment