list remote branches has commit within 30 days

44 views Asked by At

I am trying to get list of remote branch which has commit within 30 days and sort them.

git fetch
# List remote branches containing the name "selva"
branches=$(git branch -r)
# Create an empty array to store filtered branches
filtered_branches=()
# Loop through each branch
for branch in $branches; do
  # Check if the branch has commits in the last 30 days
  if git log -1 --since="30 days ago" --pretty=format:'' --abbrev-commit "$branch" >/dev/null 2>&1; then
    filtered_branches+=("$branch")
  fi
done
# Sort the filtered branches based on the oldest first
sorted_branches=($(for branch in "${filtered_branches[@]}"; do
  echo "$(git log -1 --format=%ct "$branch") $branch"
done | sort -n | cut -d' ' -f2-))

This is what I tried but its not fetching branches which has commits with in 30 days.

0

There are 0 answers