Skip to content

Clean up old branches monthly - #3004

Open
Matteo-it wants to merge 1 commit into
mainfrom
Matteo-it/clean-up-staled-branches
Open

Clean up old branches monthly#3004
Matteo-it wants to merge 1 commit into
mainfrom
Matteo-it/clean-up-staled-branches

Conversation

@Matteo-it

Copy link
Copy Markdown
Contributor

Adds a GitHub Action stale-branch-cleanup.yml that automatically removes stale remote branches. The repo has accumulated many old branches (stale, closed, already merged), and this workflow cleans them up safely.

What it does

  • Runs automatically once a month (03:00 UTC, day 1) via schedule cron.
  • Deletes remote branches whose last commit is older than 365 days.
  • Can also be triggered manually via workflow_dispatch.

Safety

  • Always skips the default branch and common protected names (main, master, develop, staging, production, gh-pages).
  • Dry-run mode: manual runs default to a simulation that only lists candidate branches without deleting. Scheduled runs perform the actual deletion.
  • Configurable days_threshold on manual runs.
  • Uses only GITHUB_TOKEN with contents: write, no extra secrets.Adds a GitHub Action (stale-branch-cleanup.yml) that automatically removes stale remote branches. The repo has accumulated many old branches (stale, closed, already merged), and this workflow cleans them up safely.

@Matteo-it
Matteo-it requested review from damianoc90 and lukdog July 8, 2026 10:21
days_threshold:
description: 'Delete branches whose last commit is older than this many days.'
required: false
default: '365'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a bit too much? Branches older than 3 months are probably already stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants