{"id":31642420,"url":"https://github.com/tagdots/delete-branches","last_synced_at":"2026-01-20T17:01:32.569Z","repository":{"id":310350095,"uuid":"1039544668","full_name":"tagdots/delete-branches","owner":"tagdots","description":"Deletes stale branches in GitHub repository","archived":false,"fork":false,"pushed_at":"2026-01-04T13:52:30.000Z","size":228,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-09T04:26:45.941Z","etag":null,"topics":["action","automation","cronjob","delete-branch","devops","github","github-branch","idle-branch","python","stale-branch","utilities"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tagdots.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","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}},"created_at":"2025-08-17T13:22:53.000Z","updated_at":"2026-01-04T13:52:32.000Z","dependencies_parsed_at":"2025-12-07T08:05:53.544Z","dependency_job_id":null,"html_url":"https://github.com/tagdots/delete-branches","commit_stats":null,"previous_names":["tagdots/delete-branches"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/tagdots/delete-branches","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tagdots%2Fdelete-branches","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tagdots%2Fdelete-branches/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tagdots%2Fdelete-branches/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tagdots%2Fdelete-branches/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tagdots","download_url":"https://codeload.github.com/tagdots/delete-branches/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tagdots%2Fdelete-branches/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28607624,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T16:10:39.856Z","status":"ssl_error","status_checked_at":"2026-01-20T16:10:39.493Z","response_time":117,"last_error":"SSL_read: 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","automation","cronjob","delete-branch","devops","github","github-branch","idle-branch","python","stale-branch","utilities"],"created_at":"2025-10-07T03:59:21.305Z","updated_at":"2026-01-20T17:01:32.527Z","avatar_url":"https://github.com/tagdots.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# delete-branches\n\n[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/11071/badge)](https://www.bestpractices.dev/projects/11071)\n[![CI](https://github.com/tagdots/delete-branches/actions/workflows/ci.yaml/badge.svg)](https://github.com/tagdots/delete-branches/actions/workflows/ci.yaml)\n[![marketplace](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/tagdots/delete-branches/refs/heads/badges/badges/marketplace.json)](https://github.com/marketplace/actions/delete-github-branches)\n[![coverage](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/tagdots/delete-branches/refs/heads/badges/badges/coverage.json)](https://github.com/tagdots/delete-branches/actions/workflows/cron-tasks.yaml)\n\n\u003cbr\u003e\n\n## ✅ What does delete-branches do?\n**delete-branches** deletes idle branches in GitHub repository.\n\n_**exemptions**_: `default branch`, `protected branches`, `head branches in PR`, and `user-specified exclude branches`\n\n\u003cbr\u003e\n\n## ⭐ Why switch to delete-branches?\n- we reduce your supply chain risks with [openssf best practices](https://best.openssf.org) in our SDLC and operations.\n- we share evidence of code coverage results in action (click _Code Coverage » cron-tasks » badge-coverage_).\n- we can run using [command line](https://github.com/tagdots/delete-branches?tab=readme-ov-file#-running-delete-branches-from-command-line) or GitHub Action [Delete GitHub Branches](https://github.com/marketplace/actions/delete-github-branches).\n\n\u003cbr\u003e\n\n## 🏃 Running _delete-branches_ in GitHub action\nUse the workflow examples below to create your own workflow inside `.github/workflows/`.\n\n\u003cbr\u003e\n\n### Example 1 - Summary (MOCK delete)\n\n| Input | Workflow Spec | Notes\n|-------|-------------|----------|\n| `scheduled run` | `- cron: '30 17 * * *'` | Run daily at 5:30 pm UTC\n| `github token permissions` | `contents: read`\u003cbr\u003e`pull-requests: read` | MOCK delete requires read permission |\n| `dry-run` | `true` | MOCK delete |\n| `exclude-branches` | `badges` | Branch `badges` is found and excluded |\n| `max-idle-days` | `10` | Without new commits longer than 10 days |\n\n### Example 1 - Workflow (MOCK delete)\n```yml\nname: delete-github-branches\n\non:\n  schedule:\n    - cron: '30 17 * * *'\n\npermissions:\n  contents: read\n  pull-requests: read\n\njobs:\n  delete-branches:\n    runs-on: ubuntu-latest\n\n    permissions:\n      contents: read\n      pull-requests: read\n\n    - name: Run delete-branches\n      id: delete-branches\n      uses: tagdots/delete-branches@1067f6cf756a462d2da56cffae2df37ea15b600e # 1.2.15\n      env:\n        GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n      with:\n        repo-url: ${{ github.server_url }}/${{ github.repository }}\n        max-idle-days: 10\n        exclude-branches: 'badges'\n        dry-run: true\n```\n\n\u003cbr\u003e\n\n### Example 2 - Summary (Permanent delete)\n| Input | Workflow Spec | Notes\n|-------|-------------|----------|\n| `scheduled run` | `- cron: '30 17 * * *'` | Run daily at 5:30 pm UTC\n| `github token permissions` | `contents: write`\u003cbr\u003e`pull-requests: read`| Delete requires write permission in `contents` |\n| `dry-run` | `false` | Permanent delete |\n| `exclude-branches` | `badges` | Branch `badges` is found and excluded |\n| `max-idle-days` | `10` | Without new commits longer than 10 days |\n\n### Example 2 - Workflow (Permanent delete)\n```yml\nname: delete-github-branches\n\non:\n  schedule:\n    - cron: '30 17 * * *'\n\npermissions:\n  contents: read\n  pull-requests: read\n\njobs:\n  delete-branches:\n    runs-on: ubuntu-latest\n\n    permissions:\n      contents: write\n      pull-requests: read\n\n    - name: Run delete-branches\n      id: delete-branches\n      uses: tagdots/delete-branches@1067f6cf756a462d2da56cffae2df37ea15b600e # 1.2.15\n      env:\n        GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n      with:\n        repo-url: ${{ github.server_url }}/${{ github.repository }}\n        max-idle-days: 10\n        exclude-branches: 'badges'\n        dry-run: false\n```\n\n\u003cbr\u003e\n\n## 🖥 Running _delete-branches_ from command line\n\n### Prerequisites\n```\n* Python (3.12+)\n* GitHub fine-grained token (contents: write)\n```\n\n\u003cbr\u003e\n\n### Setup _delete-branches_\n```\n~/work/test $ workon test\n(test) ~/work/test $ export GH_TOKEN=github_pat_xxxxxxxxxxxxx\n(test) ~/work/test $ pip install -U delete-branches\n```\n\n\u003cbr\u003e\n\n### Example 1 - Run for help\n```\n(test) ~/work/test $ delete-branches --help\nUsage: delete-branches [OPTIONS]\n\nOptions:\n  --dry-run BOOLEAN        default: true\n  --repo-url TEXT          e.g. https://github.com/{owner}/{repo}  [required]\n  --exclude-branches TEXT  e.g. 'exclude-branch-1, exclude-branch-2'\n  --max-idle-days INTEGER  Max. no. of idle days (without commits)  [required]\n  --version                Show the version and exit.\n  --help                   Show this message and exit.\n```\n\n\u003cbr\u003e\n\n### Example 2 - MOCK delete branches without new commits longer than 10 days\n| Input | Input Detail | Result\n|-------|-------------|----------|\n| `repo-url` | `https://github.com/tagdots/test` | process repository `tagdots/test` |\n| `max-idle-days` | `10` | Without new commits longer than 10 days |\n| `exclude-branches` | `test-1`, `test-2`, `badges` | Only branch `badges` is found and excluded |\n| `dry-run` | `true` | a. 3 branches exempted from delete: `main`, `badges`, `pr-branch-01`\u003cbr\u003eb. 6 branches `NOT exempt from delete`\u003cbr\u003ec. MOCK delete 2 of 6 `NOT-exempt-from-delete` branches |\n\n\u003cbr\u003e\n\n```\n(test) ~/work/test $ delete-branches --dry-run true --max-idle-days 10 --exclude-branches \"test-1, test-2, badges\" --repo-url https://github.com/tagdots/test\n\n🚀 Starting Delete GitHub Branches (dry-run: True, exclude-branches: {'test-1', 'test-2', 'badges'}, max-idle-days: 10)\n\nCurrent Time (UTC): 2025-08-20 17:08:32\n\nRefined User Exclude Branch(es): {'badges'}\nDefault Branch                 : main\nProtected Branch               : main\nPull Request Head Branch       : pr-branch-01\n\nTotal Number of Branches                         : 9\nTotal Number of Branches (Exempt-From-Delete)    : 3\nTotal Number of Branches (Not-Exempt-From-Delete): 6\n\nFrom 6 Not-Exempt-From-Delete Branch(es),  2 branch is idle more than 10 day(s)\n-------------------------------------------------------------------------------------------------\n(MOCK) Delete branch - last update UTC 2025-08-09 13:49:34: branch-test-001\n(MOCK) Delete branch - last update UTC 2025-08-08 03:29:34: branch-test-005\n```\n\n\u003cbr\u003e\n\n### Example 3 - Delete branches permanently without new commits longer than 10 days\n| Input | Input Detail | Result\n|-------|-------------|----------|\n| `repo-url` | `https://github.com/tagdots/test` | process repository `tagdots/test` |\n| `max-idle-days` | `10` | Without new commits longer than 10 days |\n| `exclude-branches` | `badges` | Branch `badges` is found and excluded |\n| `dry-run` | `false` | a. 3 branches exempted from delete: `main`, `badges`, `pr-branch-01`\u003cbr\u003eb. 6 branches `NOT exempt from delete`\u003cbr\u003ec. Delete 2 of 6 `NOT-exempt-from-delete` branches permanently |\n\n\u003cbr\u003e\n\n```\n(test) ~/work/test $ delete-branches --dry-run false --max-days 10 --exclude-branches \"badges\" --repo-url https://github.com/tagdots/test\n\n🚀 Starting Delete GitHub Branches (dry-run: False, exclude-branches: {'badges'}, max-idle-days: 10)\n\nCurrent Time (UTC): 2025-08-20 17:26:55\n\nRefined User Exclude Branch(es): {'badges'}\nDefault Branch                 : main\nProtected Branch               : main\nPull Request Head Branch       : pr-branch-01\n\nTotal Number of Branches                         : 9\nTotal Number of Branches (Exempt-From-Delete)    : 3\nTotal Number of Branches (Not-Exempt-From-Delete): 6\n\nFrom 6 Not-Exempt-From-Delete Branch(es),  2 branch is idle more than 10 day(s)\n-------------------------------------------------------------------------------------------------\n✅ Delete branch - last update UTC 2025-08-09 13:49:34: branch-test-001\n✅ Delete branch - last update UTC 2025-08-08 03:29:34: branch-test-005\n```\n\n\u003cbr\u003e\n\n## 🔧 delete-branches command line options\n\n| Input | Description | Default | Required | Notes |\n|-------|-------------|----------|----------|----------|\n| `repo-url` | Repository URL | `None` | Yes | e.g. https://github.com/{owner}/{repo} |\n| `dry-run` | Dry-Run | `True` | No | - |\n| `max-idle-days` | Maximum number of days without new commits | `None` | Yes | enter number of days |\n| `exclude-branches` | Branches excluded from deletion | `None` | No | comma seperated branches e.g. \"branch1, branch2\" |\n\n\u003cbr\u003e\n\n## 😕  Troubleshooting\n\nOpen an [issue][issues]\n\n\u003cbr\u003e\n\n## 🙏  Contributing\n\nFor pull requests to be accepted on this project, you should follow [PEP8][pep8] when creating/updating Python codes.\n\nSee [Contributing][contributing]\n\n\u003cbr\u003e\n\n## 🙌 Appreciation\nIf you find this project helpful, please ⭐ star it.  **Thank you**.\n\n\u003cbr\u003e\n\n## 📚 References\n\n[How to fork a repo](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo)\n\n\u003cbr\u003e\n\n[contributing]: https://github.com/tagdots/delete-branches/blob/main/CONTRIBUTING.md\n[issues]: https://github.com/tagdots/delete-branches/issues\n[pep8]: https://google.github.io/styleguide/pyguide.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftagdots%2Fdelete-branches","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftagdots%2Fdelete-branches","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftagdots%2Fdelete-branches/lists"}