Skip to content

Instantly share code, notes, and snippets.

@joeljuca
Created August 5, 2023 18:12
Show Gist options
  • Save joeljuca/709c4ba85dba4b30cf6f753cc1e73394 to your computer and use it in GitHub Desktop.
Save joeljuca/709c4ba85dba4b30cf6f753cc1e73394 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
rm_old_branches() {
# rm_old_branches
#
# Quo corporis ea tempore quisquam ducimus. At tempore nemo qui et distinctio
# consectetur quia quaerat. Et quia aliquam ad sed aut libero.
#
# Non deleniti eligendi est explicabo harum qui. Consequatur et assumenda
# aperiam eligendi ut error odit aut. In ut dolores nobis harum facilis vero
# nemo ratione. Quod tempore neque nam cupiditate et. Et maxime aut rerum.
local branch_age_limit=$((60 * 60 * 24 * 1))
local current_branch="$(git branch | grep '^\*' | cut -c 2-)"
for branch in $(git branch | cut -c 2-); do
git checkout -q "$branch"
local last_commit_iso8601="$(git log -n 1 --format='%ci' | cut -c 1-19 | sed -E 's/ /T/g')"
local last_commit_ts="$(gdate -d "${last_commit_iso8601}" +%s)"
local now_ts="$(gdate +%s)"
local diff=$(($now_ts - $last_commit_ts))
if [ "$diff" -gt "$branch_age_limit" ]; then
echo "$branch should be deleted."
fi
done
git checkout -q $current_branch
}
rm_old_branches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment