Created
December 10, 2015 08:54
-
-
Save pikender/f63c5067b8aac5a5eac1 to your computer and use it in GitHub Desktop.
Delete Feature Branches as Sprint Deployed on Production
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/sh | |
## Script to clean old git branches | |
echo "Delete branches having last commit before 1st June 2015 - DRY_RUN=1 to show commands - ignore if execution" | |
echo "DRY_RUN=1 delete_branches_older_than.sh '2015-06-01'" | |
echo $DRY_RUN | |
echo $1 | |
date=$1 | |
for branch in $(git branch -a | sed 's/^[ ]*//' | sed 's/^remotes\///' | grep -v 'master$'); do | |
if [[ "$(git log $branch --since $date | wc -l)" -eq 0 ]]; then | |
if [[ "$branch" =~ "origin/" ]]; then | |
local_branch_name=$(echo "$branch" | sed 's/^origin\///') | |
if [[ "$local_branch_name" =~ "pod_rev/" ]]; then | |
if [[ "$DRY_RUN" -eq 1 ]]; then | |
echo "git push origin :$local_branch_name" | |
else | |
git push origin :$local_branch_name | |
fi | |
else | |
echo "$local_branch_name NOT SCOPED" | |
fi | |
else | |
if [[ "$DRY_RUN" -eq 1 ]]; then | |
echo "git branch -D $branch" | |
else | |
git branch -D $branch | |
fi | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment