Skip to content

Simple action for deleting stale branches from GitHub repository

License

Notifications You must be signed in to change notification settings

Balvajs/delete-stale-branches

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

delete-stale-branches

Delete all branches that are stale - branches without any associated opened PRs and without any recent commits.

Useful for keeping the repository clean from leftover branches after manually closed PRs.

Usage

name: 'delete-stale-branches'
on:
  schedule:
    - cron: '0 0 * * 1'

jobs:
  delete-stale-branches:
    runs-on: ubuntu-latest
    permissions:
      contents: write # to be able to delete branches
      pull-requests: read # to be able to confirm that branches don't have associated PRs
    steps:
      - uses: balvajs/delete-stale-branches@v2
        with:
          days-to-delete: 120
          dry-run: false

Inputs

INPUT TYPE DEFAULT DESCRIPTION
days-to-delete number 90 Number of days without activity after which the branch will be deleted
dry-run boolean true If set to true, the action will only log the branches that would be deleted, but will not delete them
repository string "${{ github.repository }}" Repository name and owner in format "owner/repo"
token string "${{ github.token }}" GitHub token with pull-requests: read and contents: write permissions

* required