Skip to main content

git/cleanup_branches: clean up old Tailscale-related branches

ID
b9901dc
date
2026-06-29 08:56:26+00:00
author
Alex Chan <alexc@tailscale.com>
parent
d0928fa
message
git/cleanup_branches: clean up old Tailscale-related branches
changed files
1 file, 29 additions

Changed files

git/cleanup_branches (1213) → git/cleanup_branches (2313)

diff --git a/git/cleanup_branches b/git/cleanup_branches
index a3ee9b7..3fa8ba1 100755
--- a/git/cleanup_branches
+++ b/git/cleanup_branches
@@ -47,3 +47,32 @@ do
 
   git branch --delete "$branch"
 done
+
+# For Tailscale repos, the above check doesn't work. Branches get rebased
+# or squashed before being merged into main, so the branch never shows up
+# as merged -- it's a different commit in main and the branch.
+#
+# Instead, look for alexc/ branches that are more than a fortnight old and
+# don't exist in the origin. These are branches I've either abandoned or
+# merged into main.
+PREFIXES=("alexc/" "danni/" "icio/" "kradalby/" "mpminardi/" "mprovost/" "zofrex/")
+DAYS_AGO=14
+THRESHOLD_DATE=$(date -v-"${DAYS_AGO}"d +%s)
+
+for PREFIX in "${PREFIXES[@]}"; do
+  git for-each-ref --format='%(refname:short)' refs/heads/"$PREFIX"* | while read -r branch; do
+    # If the branch still exists on GitHub, ignore it -- this is likely
+    # an active branch with an open PR.
+    if git rev-parse --verify --quiet "origin/$branch" &>/dev/null; then
+      continue
+    fi
+
+    # When did I last commit to this branch?
+    commit_timestamp=$(git log -1 --format="%at" "$branch")
+    if (( commit_timestamp > THRESHOLD_DATE )); then
+      continue
+    fi
+  
+    git branch --delete --force "$branch"
+  done
+done