Skip to main content

Remote GitHub branch cleanup reporting tool

Project description

gh-clean

gh-clean is a remote GitHub branch cleanup tool. It evaluates branches using GitHub repository state, produces a report, and can delete branches after re-validating that they are still safe to remove.

Requirements

  • Python 3.9+
  • GitHub CLI installed
  • gh auth login completed for the target repositories

gh-clean currently uses gh for GitHub API access and authentication.

Install

With uv

Install once:

uv tool install gh-clean

Run without installing globally:

uvx gh-clean report --repo OWNER/REPO

With pipx

pipx install gh-clean

Authenticate

Before using the tool:

gh auth login

If your org requires SAML SSO, authorize the current gh token for that organization as needed.

Repository config

The target repository must contain a root .gh-clean.yml file with a non-empty protected_branches list.

Example:

protected_branches:
  - main
  - staging
  - production

This list is checked in addition to GitHub branch protection rules and rulesets.

If you need a one-off run before the config is committed, you can bypass the remote file with a CLI override:

gh-clean report --repo OWNER/REPO --protected-branches main,staging,production

Usage

Generate a report:

gh-clean report --repo OWNER/REPO
gh-clean report --repo OWNER/REPO --format json
gh-clean report --repo OWNER/REPO --protected-branches main,staging,production

Add extra protected branches at runtime:

gh-clean report --repo OWNER/REPO --exclude develop --exclude release/v2

Delete from a prior report with re-validation:

gh-clean report --repo OWNER/REPO --format json > report.json
gh-clean delete --repo OWNER/REPO --input report.json --recommendation delete-candidate --dry-run
gh-clean delete --repo OWNER/REPO --input report.json --recommendation delete-candidate
gh-clean delete --repo OWNER/REPO --input report.json --recommendation delete-candidate --protected-branches main,staging,production

Delete specific branches:

gh-clean delete --repo OWNER/REPO --branch feature/foo --branch feature/bar --dry-run

Override only the merged-tip mismatch soft veto:

gh-clean delete --repo OWNER/REPO --branch feature/foo --force-merged-tip-mismatch --dry-run

Development

Run directly from the checkout:

python3 -m gh_clean report --repo gh-clean-sandbox/sandbox
uv run gh-clean report --repo gh-clean-sandbox/sandbox

Run tests:

python3 -m unittest discover -s tests -v

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

gh_clean-0.1.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

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

gh_clean-0.1.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file gh_clean-0.1.0.tar.gz.

File metadata

  • Download URL: gh_clean-0.1.0.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for gh_clean-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7467cf854f78418f63f1c8c14863b643964d29cf27d01a98b001b78847eff6a4
MD5 cf85cb63e9a86abd1c7984acbfcb29e7
BLAKE2b-256 953394c7f40964258e105be136cb100977a508bd665b9057eb8a2bda0111c185

See more details on using hashes here.

File details

Details for the file gh_clean-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gh_clean-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for gh_clean-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9444c44f61e198d45733682f75f419465c5321e385e13460fd377cc38ee89c35
MD5 8aba17ce82a535cd9554780c432d3a5d
BLAKE2b-256 a2b46e8f9dea5fb08a3f638e53de717f0eb6a338b62d48527c3bc9b37352faf4

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