Skip to main content

No project description provided

Project description

delete-branches

OpenSSF Best Practices CI marketplace coverage


✅ What does delete-branches do?

delete-branches removes GitHub branches that have been inactive (without new commits) for longer than the idle period.

exemptions: default branch, protected branches, head branches in PR, and user-specified exclude branches


⭐ Why switch to delete-branches?

  • we reduce your supply chain risks with openssf best practices in our SDLC and operations.
  • we share evidence of code coverage results in action (click Code Coverage » cron-tasks » badge-coverage).

🏃 Running delete-branches in GitHub action

Use the workflow examples below to create your own workflow inside .github/workflows/.


Example 1 - MOCK Delete Summary

  • run on a scheduled interval - every day at 5:30 pm UTC (- cron: '30 17 * * *')
  • use GitHub Token with permissions: contents: read
  • exclude branch from delete: badges (exclude-branches: 'badges')
  • perform a MOCK delete (dry-run: true)
  • display inactive branches without new commits longer than 10 days (max-idle-days: 10)

Example 1 - MOCK Delete Workflow

name: delete-github-branches

on:
  schedule:
    - cron: '30 17 * * *'

permissions:
  contents: read

jobs:
  delete-branches:
    runs-on: ubuntu-latest

    permissions:
      contents: read
      pull-requests: read

    - name: Run delete-branches
      id: delete-branches
      uses: tagdots/delete-branches@ff424d3a4af5b29492bd8b778887583259b3e573 # 1.0.0
      env:
        GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        repo-url: ${{ github.repository }}
        max-idle-days: 10
        exclude-branches: 'badges'
        dry-run: true

Example 2 - Irreversible Delete Summary

  • run on a scheduled interval - every day at 5:30 pm UTC (- cron: '30 17 * * *')
  • use GitHub Token with permissions: contents: write
  • exclude branch from delete: badges (exclude-branches: 'badges')
  • perform a delete (dry-run: false)
  • delete inactive branches without new commits longer than 10 days (max-idle-days: 10)

Example 2 - Irreversible Delete Workflow

name: delete-github-branches

on:
  schedule:
    - cron: '30 17 * * *'

permissions:
  contents: read

jobs:
  delete-branches:
    runs-on: ubuntu-latest

    permissions:
      contents: write
      pull-requests: read

    - name: Run delete-branches
      id: delete-branches
      uses: tagdots/delete-branches@ff424d3a4af5b29492bd8b778887583259b3e573 # 1.0.0
      env:
        GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        repo-url: ${{ github.repository }}
        max-idle-days: 10
        exclude-branches: 'badges'
        dry-run: false

🖥 Running delete-branches locally

Prerequisites

* Python (3.12+)
* GitHub fine-grained token (contents: write)

Setup delete-branches

~/work/hello-world $ workon hello-world
(hello-world) ~/work/hello-world $ export GH_TOKEN=github_pat_xxxxxxxxxxxxx
(hello-world) ~/work/hello-world $ pip install -U delete-branches

🔍 Example 1 - Run for help

(hello-world) ~/work/hello-world $ delete-branches --help
Usage: delete-branches [OPTIONS]

Options:
  --dry-run BOOLEAN        default: true
  --repo-url TEXT          e.g. https://github.com/{owner}/{repo}  [required]
  --exclude-branches TEXT  Branches excluded from deletion
  --max-idle-days TEXT     Delete branches older than max. idle days [required]
  --version                Show the version and exit.
  --help                   Show this message and exit.

🔍 Example 2 - MOCK delete branches with no commits longer than 10 days

Summary

  1. exclude 3 branches: test-1, test-2, badges
  2. remove branches without commits longer than 10 days

Results

  1. refine excluded branches to badges because branches (test-1 and test-2) do not exist
  2. 3 branches are exempted from delete: main, badges, pr-branch-01
  3. 6 branches are not exempted from delete and 2 out of 6 had no commits in the last 10 days
  4. mock delete 2 branches
(hello-world) ~/work/hello-world $ delete-branches --dry-run true --max-idle-days 10 --repo-url https://github.com/tagdots/hello-world --exclude-branches "test-1, test-2, badges"

🚀 Starting to Delete GitHub Branches (dry-run: True, exclude-branches: {'test-1', 'test-2', 'badges'}, max-idle-days: 10)

Current Time (UTC): 2025-08-20 17:08:32

Refined User Exclude Branch(es): {'badges'}
Default Branch                 : main
Protected Branch               : main
Pull Request Head Branch       : pr-branch-01

Total Number of Branches                         : 9
Total Number of Branches (Exempt-From-Delete)    : 3
Total Number of Branches (Not-Exempt-From-Delete): 6

From 6 Not-Exempt-From-Delete Branch(es),  2 had no commits in the last 10 day(s)
-------------------------------------------------------------------------------------------------
(MOCK) Delete branch - last update UTC 2025-08-09 13:49:34: branch-test-001
(MOCK) Delete branch - last update UTC 2025-08-08 03:29:34: branch-test-005

🔍 Example 3 - Delete branches with no commits longer than 10 days

Summary

  1. exclude 1 branch: badges
  2. remove branches without commits longer than 10 days

Results

  1. refine excluded branches to badges
  2. 3 branches are exempted from delete: main, badges, pr-branch-01
  3. 6 branches are not exempted from delete and 2 out of 6 had no commits in the last 10 days
  4. delete 2 branches
(hello-world) ~/work/hello-world $ delete-branches --dry-run false --max-days 10 --repo-url https://github.com/tagdots/hello-world --exclude-branches "badges"

🚀 Starting to Delete GitHub Branches (dry-run: True, exclude-branches: {'badges'}, max-idle-days: 10)

Current Time (UTC): 2025-08-20 17:26:55

Refined User Exclude Branch(es): {'badges'}
Default Branch                 : main
Protected Branch               : main
Pull Request Head Branch       : pr-branch-01

Total Number of Branches                         : 9
Total Number of Branches (Exempt-From-Delete)    : 3
Total Number of Branches (Not-Exempt-From-Delete): 6

From 6 Not-Exempt-From-Delete Branch(es),  2 had no commits in the last 10 day(s)
-------------------------------------------------------------------------------------------------
✅ Delete branch - last update UTC 2025-08-09 13:49:34: branch-test-001
✅ Delete branch - last update UTC 2025-08-08 03:29:34: branch-test-005

🔧 delete-branches command line options

Input Description Default Required Notes
repo-url Repository URL None Yes e.g. https://github.com/{owner}/{repo}
dry-run Dry-Run True No -
max-idle-days Maximum number of days without commits None No enter number of days
exclude-branches Branches excluded from deletion None No comma seperated branches e.g. "branch1, branch2"

😕 Troubleshooting

Open an issue


🙏 Contributing

For pull requests to be accepted on this project, you should follow PEP8 when creating/updating Python codes.

See Contributing


🙌 Appreciation

If you find this project helpful, please ⭐ star it. Thank you.


📚 References

How to fork a repo


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

delete_branches-1.1.1.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

delete_branches-1.1.1-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file delete_branches-1.1.1.tar.gz.

File metadata

  • Download URL: delete_branches-1.1.1.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for delete_branches-1.1.1.tar.gz
Algorithm Hash digest
SHA256 b1b24be9cfacb392b423c97446889e7e82a41b9596f5550f46ee51b4af3cae45
MD5 96dfaf97a2d23f26ef535c93bacef8aa
BLAKE2b-256 885b2960f29a63a35ae075f20db1239680783f740041ceb863d77e64cc9a5cbf

See more details on using hashes here.

File details

Details for the file delete_branches-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for delete_branches-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7449eb20dfdbc9f07818aaf55a01ce5c4d5331745737b21cf8a492dfbf78b00f
MD5 498fe2f1f28d22f8233247dbf94ff22a
BLAKE2b-256 4121fdf7463ba9ccc7efbfa696c4a77eb5f72d4b35b4fae66bd4d3b0853bfa18

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page