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 deletes idle branches in GitHub repository.

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


⭐ Why switch to delete-branches?


🏃 Running delete-branches in GitHub action

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


Example 1 - Summary (MOCK delete)

Input Workflow Spec Notes
scheduled run - cron: '30 17 * * *' Run daily at 5:30 pm UTC
github token permissions contents: read
pull-requests: read
MOCK delete requires read permission
dry-run true MOCK delete
exclude-branches badges Branch badges is found and excluded
max-idle-days 10 Without new commits longer than 10 days

Example 1 - Workflow (MOCK delete)

name: delete-github-branches

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

permissions:
  contents: read
  pull-requests: 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@774994b535b7853251f338762a0b5fe829eece09 # 1.1.1
      env:
        GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        repo-url: ${{ github.repository }}
        max-idle-days: 10
        exclude-branches: 'badges'
        dry-run: true

Example 2 - Summary (Irreversible delete)

Input Workflow Spec Notes
scheduled run - cron: '30 17 * * *' Run daily at 5:30 pm UTC
github token permissions contents: write
pull-requests: read
Delete requires write permission in contents
dry-run false Irreversible delete
exclude-branches badges Branch badges is found and excluded
max-idle-days 10 Without new commits longer than 10 days

Example 2 - Workflow (Irreversible delete)

name: delete-github-branches

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

permissions:
  contents: read
  pull-requests: 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@774994b535b7853251f338762a0b5fe829eece09 # 1.1.1
      env:
        GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        repo-url: ${{ github.repository }}
        max-idle-days: 10
        exclude-branches: 'badges'
        dry-run: false

🖥 Running delete-branches from command line

Prerequisites

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

Setup delete-branches

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

Example 1 - Run for help

(test) ~/work/test $ 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     Max. no. of idle days (without new commits) [required]
  --version                Show the version and exit.
  --help                   Show this message and exit.

Example 2 - MOCK delete branches without new commits longer than 10 days

Input Input Detail Result
repo-url https://github.com/tagdots/test process repository tagdots/test
max-idle-days 10 Without new commits longer than 10 days
exclude-branches test-1, test-2, badges Only branch badges is found and excluded
dry-run true a. 3 branches exempted from delete: main, badges, pr-branch-01
b. 6 branches NOT exempt from delete
c. MOCK delete 2 of 6 NOT-exempt-from-delete branches

(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

🚀 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 permanently without new commits longer than 10 days

Input Input Detail Result
repo-url https://github.com/tagdots/test process repository tagdots/test
max-idle-days 10 Without new commits longer than 10 days
exclude-branches badges Branch badges is found and excluded
dry-run false a. 3 branches exempted from delete: main, badges, pr-branch-01
b. 6 branches NOT exempt from delete
c. Delete 2 of 6 NOT-exempt-from-delete branches permanently

(test) ~/work/test $ delete-branches --dry-run false --max-days 10 --exclude-branches "badges" --repo-url https://github.com/tagdots/test

🚀 Starting to Delete GitHub Branches (dry-run: False, 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 new commits None Yes 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.3.tar.gz (12.4 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.3-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: delete_branches-1.1.3.tar.gz
  • Upload date:
  • Size: 12.4 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.3.tar.gz
Algorithm Hash digest
SHA256 eaa9070bb4b2d4dbe04b6e41aee1cc46723be1a645b6c2f8be052a7b6109906f
MD5 60e7fbc8133628b865797b1b445c790e
BLAKE2b-256 157ad675f752bafa99e20cb5f5de0dd628f5899b07f74f37a2536467069ca064

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for delete_branches-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e8ba19f951aa395ded7ebcf1d99145a92e6c9e58513b8e0f90bd42a1c48c4216
MD5 bfbf4ba948453646d938d6233778b525
BLAKE2b-256 6ef43fbf300e20d71915f727f045fa6c9c7487f808821abf42704b1cc95e13c3

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