Created
August 31, 2022 14:02
Revisions
-
akhileshdarjee created this gist
Aug 31, 2022 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ #!/bin/bash ## # Script to delete remote git branches ## # Fetch the remote resources git fetch # Loop through all remote merged branches count=0 date='Sep 1, 2021' echo "Branches that are older than $date" for branch in $(git branch -r --merged | grep -v HEAD | grep -v develop | grep -v master | grep -v master | sed /\*/d); do if [ -z "$(git log -1 --since="$date" -s ${branch})" ]; then echo -e `git show --format="%ci %cr %an" ${branch} | head -n 1` \\t$branch count=$((count + 1)) remote_branch=$(echo ${branch} | sed 's#origin/##' ) # To delete the branches uncomment the bellow git delete command #git push origin --delete ${remote_branch} fi done echo "Found $count merged branches that have no commits since $date"