I want to list all 1 year before git branches and then ask user to type YES tto delete all the listed branches.
#!/bin/bash
if [[ "$data_folder" == "test" ]]; then
current_timestamp=$(date +%s)
twelve_months_ago=$(( $current_timestamp - 12*30*24*60*60 ))
for x in `git branch -r | sed /\*/d`; do
branch_timestamp=$(git show -s --format=%at $x)
if [[ "$branch_timestamp" -lt "$twelve_months_ago" ]]; then
branch_for_removal+=("${x/origin\//}")
fi
done
if [[ "$USERCHOICE" == "YES" ]]; then
git push origin --delete ${branch_for_removal[*]}
echo "Finish!"
else
echo "Exit"
fi
Is this logic correct to list and delete all 1 year before git branches !!