Skip to main content

No project description provided

Project description

delete-branches

OpenSSF Best Practices CI marketplace coverage


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 practices in our SDLC and operations.
  • we share evidence of coverage run test 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

  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.0.0.tar.gz (11.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.0.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

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

Hashes for delete_branches-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4ac378c3a6bfd5e7f8e894b841b92b8e96f28da0e27b12f2ae7086222b364682
MD5 9fc8793e1b02d88d22a7cfe9d0490273
BLAKE2b-256 62c9fa28fed0a60b6703fbd94b6328c8046b1a924ac9ee3f36c13943b75caa2a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for delete_branches-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9d270cb6d8a8dad8b3ec48a09c1d2c6ef70e29d72ba7cc13dd84b7e640fc579d
MD5 8b11248f0a3c2c6526ac1462b581f972
BLAKE2b-256 9e93365272d683c37f9a1ed54d115dbf675f77a8f2473ffd065d6bb409999048

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