{"id":15692258,"url":"https://github.com/cbrgm/cleanup-stale-branches-action","last_synced_at":"2026-02-12T04:23:53.300Z","repository":{"id":217732675,"uuid":"744686287","full_name":"cbrgm/cleanup-stale-branches-action","owner":"cbrgm","description":"Use this Action to cleanup stale / abandoned branches in your GitHub repository","archived":false,"fork":false,"pushed_at":"2026-01-22T17:42:11.000Z","size":205,"stargazers_count":15,"open_issues_count":1,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-01-23T10:35:30.395Z","etag":null,"topics":["action","branches","cleanup","container","dirk","github","github-actions","go","stale"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cbrgm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"ko_fi":"chrisbargmann"}},"created_at":"2024-01-17T19:59:42.000Z","updated_at":"2026-01-22T17:42:15.000Z","dependencies_parsed_at":"2024-03-05T02:46:58.225Z","dependency_job_id":"4aa797a7-ca89-4fd4-a591-b9227fbc8991","html_url":"https://github.com/cbrgm/cleanup-stale-branches-action","commit_stats":{"total_commits":61,"total_committers":4,"mean_commits":15.25,"dds":0.5573770491803278,"last_synced_commit":"fef159c7cf504981de2cbe7980de6267ed1e2f69"},"previous_names":["cbrgm/cleanup-stale-branches-action"],"tags_count":42,"template":false,"template_full_name":null,"purl":"pkg:github/cbrgm/cleanup-stale-branches-action","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbrgm%2Fcleanup-stale-branches-action","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbrgm%2Fcleanup-stale-branches-action/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbrgm%2Fcleanup-stale-branches-action/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbrgm%2Fcleanup-stale-branches-action/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cbrgm","download_url":"https://codeload.github.com/cbrgm/cleanup-stale-branches-action/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbrgm%2Fcleanup-stale-branches-action/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28980159,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T13:38:33.235Z","status":"ssl_error","status_checked_at":"2026-02-01T13:38:32.912Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["action","branches","cleanup","container","dirk","github","github-actions","go","stale"],"created_at":"2024-10-03T18:30:14.835Z","updated_at":"2026-02-01T14:02:34.550Z","avatar_url":"https://github.com/cbrgm.png","language":"Go","funding_links":["https://ko-fi.com/chrisbargmann"],"categories":[],"sub_categories":[],"readme":"# Cleanup Stale Branches Action\n\n**Automatically delete abandoned / stale branches from a GitHub repository**\n\n[![GitHub release](https://img.shields.io/github/release/cbrgm/cleanup-stale-branches-action.svg)](https://github.com/cbrgm/cleanup-stale-branches-action)\n[![Go Report Card](https://goreportcard.com/badge/github.com/cbrgm/cleanup-stale-branches-action)](https://goreportcard.com/report/github.com/cbrgm/cleanup-stale-branches-action)\n[![go-lint-test](https://github.com/cbrgm/cleanup-stale-branches-action/actions/workflows/go-lint-test.yml/badge.svg)](https://github.com/cbrgm/cleanup-stale-branches-action/actions/workflows/go-lint-test.yml)\n[![go-binaries](https://github.com/cbrgm/cleanup-stale-branches-action/actions/workflows/go-binaries.yml/badge.svg)](https://github.com/cbrgm/cleanup-stale-branches-action/actions/workflows/go-binaries.yml)\n[![container](https://github.com/cbrgm/cleanup-stale-branches-action/actions/workflows/container.yml/badge.svg)](https://github.com/cbrgm/cleanup-stale-branches-action/actions/workflows/container.yml)\n\n## Stale / Abandoned Branch Criteria\n\nThis GitHub Action deems a branch as stale or abandoned based on the following criteria:\n\n- 🚫 **Not Default Branch**: The branch is not the repository's default branch.\n- 🛡️ **Not Protected**: The branch is not a protected branch.\n- 📭 **No Open Pull Requests**: There are no open pull requests that originate from the branch.\n- 🔀 **Not Base of an Open Pull Request**: The branch is not the base branch for any open pull requests.\n- 🚫 **Not in Ignore List**: The branch is not included in the optional list of branches to ignore.\n- ❌ **(No) Branch Prefix Match**: If specified, the branch name does (not) match one of the given prefixes.\n- ⏰ **Latest Commit Age**: The branch's last commit is older than the specified number of days (e.g., no commits for 30 days).\n\nBranches that meet all these criteria are considered as stale or abandoned and eligible for deletion.\n\n## Inputs\n\n- `token`: **Required** - GitHub token for authentication. Use GitHub secrets for security.\n- `repository`: **Required** - The target GitHub repository in the format \"owner/repo\".\n- `ignore-branches`: Optional - Comma-separated list of branches to ignore from deletion.\n- `allowed-prefixes`: Optional - Comma-separated list of prefixes a branch must match to be considered for deletion.\n- `ignored-prefixes`: Optional - Comma-separated list of prefixes a branch must NOT match to be considered for deletion.\n- `last-commit-age-days`: Optional - Number of days since the last commit for a branch to be considered abandoned. Defaults to `30` days.\n- `dry-run`: Optional - Perform a dry run without actually deleting branches. Defaults to `true`, meaning no branches will be deleted.\n- `rate-limit`: Optional - Stop the action if it exceeds 95% of the GitHub API rate limit. Defaults to `true`, ensuring the action is halted before hitting the rate limit e.g. exiting with status code `0` instead of failing.\n- `github-enterprise-url`: Optional - Allows the action to be used with GitHub Enterprise instances. Specify the url of your GitHub Enterprise instance (e.g., `https://github.mycompany.com`).\n\n### Container Usage\n\nThis action can be executed independently from workflows within a container. To do so, use the following command:\n\n```\npodman run --rm -it ghcr.io/cbrgm/cleanup-stale-branches-action:v1 --help\n```\n\n### Workflow Usage\n\n```yaml\nname: Cleanup Stale Branches\n\non:\n  workflow_dispatch:\n  schedule:\n    - cron: '0 0 * * *' # This schedule runs the workflow at midnight every day\n\njobs:\n  cleanup-stale-branches:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Cleanup Stale Branches\n        uses: cbrgm/cleanup-stale-branches-action@v1\n        with:\n          token: ${{ secrets.GITHUB_TOKEN }}\n          repository: ${{ github.repository }}\n```\n\n### Example Workflow: Run Cleanup on Schedule\n\nThis advanced example includes optional configurations:\n\n```yaml\nname: Cleanup Stale Branches\n\non:\n  workflow_dispatch:\n  schedule:\n    - cron: '0 0 * * *' # This schedule runs the workflow at midnight every day\n\njobs:\n  cleanup-stale-branches:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Cleanup Stale Branches\n        uses: cbrgm/cleanup-stale-branches-action@v1\n        with:\n          token: ${{ secrets.GITHUB_TOKEN }}\n          repository: ${{ github.repository }}\n          ignore-branches: \"foobar,release-*\"\n          ignored-prefixes: \"feature/,bugfix/\"\n          last-commit-age-days: 60\n          dry-run: false\n          rate-limit: true\n```\n\nIn this advanced example:\n\n* The action is scheduled to run daily.\n* It ignores the branch `foobar` and branches starting with `release-`.\n* Branches prefixed with `feature/` or `bugfix/` are not considered for deletion.\n* Branches with no commits in the last `60` days are eligible for deletion.\n* The action is not in `dry-run` mode, meaning branches will actually be deleted.\n* The `rate-limit` check is enabled to prevent exceeding the GitHub API rate limit.\n\n### High-level Functionality\n\n```mermaid\nsequenceDiagram\n    participant GitHubAction\n    participant GitHubAPI\n\n    Note over GitHubAction,GitHubAPI: GitHub Action: cleanup-stale-branches-action\n\n    GitHubAction-\u003e\u003eGitHubAPI: Initialize (Token, Repo Info)\n    activate GitHubAPI\n    GitHubAPI--\u003e\u003eGitHubAction: Repository Validated\n\n    loop For each Branch in Repository\n        GitHubAction-\u003e\u003eGitHubAPI: Fetch Branch Details\n        GitHubAPI--\u003e\u003eGitHubAction: Return Branch Details\n        GitHubAction-\u003e\u003eGitHubAction: Evaluate Branch Deletion Criteria\n        alt Branch Meets Criteria\n            alt Dry Run Enabled\n                GitHubAction-\u003e\u003eGitHubAction: Log Deletable Branch (No Action)\n            else Dry Run Disabled\n                GitHubAction-\u003e\u003eGitHubAPI: Delete Branch\n                GitHubAPI--\u003e\u003eGitHubAction: Branch Deleted\n            end\n        else Branch Does Not Meet Criteria\n            GitHubAction-\u003e\u003eGitHubAction: Log Skipping Branch\n        end\n    end\n\n    deactivate GitHubAPI\n```\n\n### Local Development\n\nYou can build this action from source using `Go`:\n\n```bash\nmake build\n```\n\n## Disclaimer\n\nUsage of this action is entirely at your own risk. While this action has been thoroughly tested, there is always the potential for unexpected behavior, especially in different or complex repository setups. I am not responsible for any damage, data loss, or unexpected code deletion that might occur due to misconfiguration or unexpected behavior of this action. Please ensure you have understood the functionality and have correctly configured the action according to your requirements before using it in a production environment.\n\n## Contributing \u0026 License\n\nWe welcome and value your contributions to this project! 👍 If you're interested in making improvements or adding features, please refer to our [Contributing Guide](https://github.com/cbrgm/cleanup-stale-branches-action/blob/main/CONTRIBUTING.md). This guide provides comprehensive instructions on how to submit changes, set up your development environment, and more.\n\nPlease note that this project is developed in my spare time and is available for free 🕒💻. As an open-source initiative, it is governed by the [Apache 2.0 License](https://github.com/cbrgm/cleanup-stale-branches-action/blob/main/LICENSE). This license outlines your rights and obligations when using, modifying, and distributing this software.\n\nYour involvement, whether it's through code contributions, suggestions, or feedback, is crucial for the ongoing improvement and success of this project. Together, we can ensure it remains a useful and well-maintained resource for everyone 🌍.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcbrgm%2Fcleanup-stale-branches-action","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcbrgm%2Fcleanup-stale-branches-action","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcbrgm%2Fcleanup-stale-branches-action/lists"}