0

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.

  • This doesn't account for the 30 days part, but will sort the remote branches for you by date, oldest first: `git branch -r --sort=committerdate` (And you can use `--sort=-committerdate` to sort descending.) – TTT Jul 10 '23 at 21:19
  • 1
    `grep "$selva"` doesn't filter lines containing the name "selva". Do you have an env var `selva` defined? Among the remote branches filtered with `grep` are you sure there're branches which have commits within last 30 days? – phd Jul 11 '23 at 00:23
  • @phd @TTT help me with the script that can fetch branch has commit within 30 days.. Ignore `grep` part – Selvathalapathy S Jul 11 '23 at 07:40

0 Answers0