Add stale branch cleanup workflow and lifecycle policy#15680
Add stale branch cleanup workflow and lifecycle policy#15680HariniMalothu17 merged 4 commits intomicrosoft:mainfrom
Conversation
|
I believe you tested these changes in your fork. Also confirm once that it is not deleting any protected branches. Don't Merge this PR on Monday. |
I tested this in my fork and confirmed that we can list all branches, that's good. What is your view @iamAbhi-916 |
yeah, we should have a manual trigger, but we are deleting for 90-days of inactivity so this should be okay |
Monday run will not delete any branches |



Description
Introduces a GitHub Action to automatically clean up stale branches and a documentation page outlining the branch lifecycle policy.
Changes
cleanup-stale-branches.yml
Scheduled to run every Monday at 08:00 UTC
Can also be triggered manually with a dry-run option for previewing
Two-tier staleness thresholds:
copilot/* branches: 90 days
All other branches: 180 days
Protected branches (never deleted):
main, master, develop
release/, hotfix/, archive/*
-stable (e.g., 0.72-stable, 0.80-stable)
preview- (e.g., preview-0.80-test)
Skips branches with open PRs (including drafts)
If you need to keep a branch from being deleted, Rename it under archive/
branch-lifecycle-policy.md
Documents the cleanup policy, thresholds, and protected patterns
Explains how to preserve a branch from cleanup
FAQ for common questions
Motivation
The repository has accumulated many stale branches over time. This workflow helps maintain a clean branch list by automatically removing inactive branches while protecting important ones (stable releases, previews, branches with open PRs).
Testing
Ran the workflow manually in dry-run mode — completed successfully in 20s
Verified protected branch patterns against existing repo branches
Type of Change
Resolves #15034
Microsoft Reviewers: Open in CodeFlow