No project description provided
Project description
delete-branches
delete-branches removes GitHub branches that have been inactive (without new commits) for longer than the idle period.
exemption
- default branch
- protected branches
- head branches in PR
- user-specified exclude branches
⭐ Why switch to delete-branches?
- we reduce your supply chain risks with
openssf best practicesin our SDLC and operations. - we share evidence of
coverage runtest results in action (click Code Coverage badge).
🏃 Running delete-branches-action in GitHub action
Please visit our GitHub action (delete-branches-action) on the GitHub Marketplace.
🖥 Running delete-branches locally
Prerequisites
* Python (3.12+)
* GitHub fine-grained token (contents: write)
Install 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
- exclude 3 branches:
'test-1','test-2','badges' - remove branches without commits longer than 10 days
Results
- refine excluded branches to
{'badges'}because branches (test-1andtest-2) do not exist - 3 branches are exempted from delete:
main,badges,pr-branch-01 - 6 branches are not exempted from delete and 2 out of 6 had no commits in the last 10 days
- 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
- exclude 1 branch:
'badges' - remove branches without commits longer than 10 days
Results
- refine excluded branches to
{'badges'} - 3 branches are exempted from delete:
main,badges,pr-branch-01 - 6 branches are not exempted from delete and 2 out of 6 had no commits in the last 10 days
- 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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file delete_branches-1.0.0.tar.gz.
File metadata
- Download URL: delete_branches-1.0.0.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ac378c3a6bfd5e7f8e894b841b92b8e96f28da0e27b12f2ae7086222b364682
|
|
| MD5 |
9fc8793e1b02d88d22a7cfe9d0490273
|
|
| BLAKE2b-256 |
62c9fa28fed0a60b6703fbd94b6328c8046b1a924ac9ee3f36c13943b75caa2a
|
File details
Details for the file delete_branches-1.0.0-py3-none-any.whl.
File metadata
- Download URL: delete_branches-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d270cb6d8a8dad8b3ec48a09c1d2c6ef70e29d72ba7cc13dd84b7e640fc579d
|
|
| MD5 |
8b11248f0a3c2c6526ac1462b581f972
|
|
| BLAKE2b-256 |
9e93365272d683c37f9a1ed54d115dbf675f77a8f2473ffd065d6bb409999048
|