Skip to main content

Report and clean up stale GitHub branches with Slack notifications

Workflow preview

Workflow preview
100%
Report and clean up stale GitHub branches with Slack notifications preview
Open on n8n.io

1. Workflow Overview

Quick Overview This workflow runs weekly (or manually) to scan GitHub repositories for merged but not deleted and stale branches, then posts a cleanup report to Slack and can optionally auto delete...

Best for

  • DevOps automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-base.stickynote, n8n-nodes-base.scheduletrigger, n8n-nodes-base.set, n8n-nodes-base.code, n8n-nodes-base.httprequest, n8n-nodes-base.slack, n8n-nodes-base.if, n8n-nodes-base.manualtrigger

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Adriaan van Niekerk.

Original n8n.io source

1.1 Workflow description

Title
Report and clean up stale GitHub branches with Slack notifications
Workflow name
Report and clean up stale GitHub branches with Slack notifications

Quick Overview

This workflow runs weekly (or manually) to scan GitHub repositories for merged-but-not-deleted and stale branches, then posts a cleanup report to Slack and can optionally auto-delete a capped number of branches.

How it works

  1. Runs on a weekly schedule or when you manually execute the workflow.
  2. Loads configuration for the GitHub repo owner, repository list, stale age threshold, protected branch patterns, Slack channel, and deletion limits.
  3. For each configured repository, fetches all branches via the GitHub GraphQL API and fetches recently merged pull requests via the GitHub REST API.
  4. Classifies branches as protected (skipped), merged-but-not-deleted, or stale based on last commit date and the configured stale-days threshold.
  5. If auto-delete is enabled, deletes up to the configured maximum number of candidate branches in GitHub and compiles a success/failure summary.
  6. Formats and posts the cleanup report to Slack, and if deletions ran, posts a second Slack message with the deletion results.

Setup

  1. Create and add GitHub credentials (fine-grained token or PAT) with access to list branches/PRs and permission to delete branches if you enable auto-delete.
  2. Create and add a Slack credential with permission to post messages (chat:write) and set the target channel in the configuration.
  3. Update the configuration values for repo owner, comma-separated repo list, staleDays, protectedBranches, reportOnly, and maxBranchesToDelete before activating the workflow.

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Main — Branch Cleanup Reporter

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 2 - Section — Collect

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 3 - Section — Analyze

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 4 - Section — Report

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 5 - Section — Delete

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 6 - Credentials & Safety Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 7 - Weekly Schedule Trigger

Type / Role
n8n-nodes-base.scheduleTrigger - scheduleTrigger
Config choices
Version 1.3

Block 8 - Configuration

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 9 - Expand Repo List

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 10 - Fetch All Branches

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.4

Block 11 - Fetch Recently Merged PRs

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.4

Block 12 - Classify Branches — Merged vs Stale

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 13 - Format Cleanup Report

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 14 - Send Report to Slack

Type / Role
n8n-nodes-base.slack - slack
Config choices
Version 2.2

Block 15 - Auto-Delete Enabled?

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.3

Block 16 - Split Branches for Deletion

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 17 - Delete Single Branch

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.4

Block 18 - Summarize Deletion Results

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 19 - Send Cleanup Summary to Slack

Type / Role
n8n-nodes-base.slack - slack
Config choices
Version 2.2

Block 20 - When clicking ‘Execute workflow’

Type / Role
n8n-nodes-base.manualTrigger - manualTrigger
Config choices
Version 1

3. Summary Table

Workflow Report and clean up stale GitHub branches with Slack notifications
Complexity advanced
Nodes 20
Categories DevOps
Author Adriaan van Niekerk
Published 09 Jun 2026

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/16220/16220.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Report and clean up stale GitHub branches with Slack notifications do?

Quick Overview This workflow runs weekly (or manually) to scan GitHub repositories for merged but not deleted and stale branches, then posts a cleanup report to Slack and can optionally auto delete...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your DevOps use case.