MergeMe logoMergeMe
Published on

GitHub Slack branch filters: Fix commit notifications

Authors
  • Name
    Maruan

GitHub Slack branch filters of the form commits:BRANCH scope commit notifications only. They do not filter pull request, review, issue or workflow events, and workflow branch filtering is a separate setting. If your branch filter seems to do nothing, or the wrong messages keep appearing, first check whether the message was a commit notification.

This guide covers the official GitHub app for Slack and nothing else. It lists the branch options the current documentation gives, shows an isolated way to test a filter, and explains how to work out which event type actually posted. The commands below are illustrative. They come from the official docs and were not run for this article, so confirm the output in your own workspace.

The short answer: commits:BRANCH only scopes commit notifications

A branch filter in the official GitHub app narrows the commits feature and nothing more. The documentation describes branch filters as a way to filter commit notifications based on branch names. There is no documented branch filter for pull requests, reviews, issues or comments.

That explains the most common complaint. You set a filter such as commits:main, a pull request opened against a different branch still shows up in the channel, and it looks like the filter failed. It didn't. Pull request notifications are a separate feature, and the commit filter was never applied to them.

Workflow notifications have their own branch setting too, covered further down. Each feature has its own scope, so diagnose them one at a time.

The branch options the official GitHub app documents

The documentation gives a short list of commit branch options. Don't assume anything outside that list works.

By default, commit notifications cover the default branch only. To subscribe to commits explicitly, use the subscribe command with the commits feature:

/github subscribe OWNER/REPO commits

To target one named branch, add it after a colon:

/github subscribe OWNER/REPO commits:main

To target a family of branches with a wildcard, the docs show a pattern like this:

/github subscribe OWNER/REPO commits:feature/*

To receive commits from every branch:

/github subscribe OWNER/REPO commits:*

There is one more form you may find in older configs. The docs note that commits:all is closing down, and that existing configurations keep working until they are updated. If you inherited a channel that uses it, replace it with commits:* rather than waiting for it to disappear.

Don't invent syntax beyond this. The documentation does not describe regular expressions, negated patterns that exclude a branch, or branch filters on pull request events. Do not assume undocumented syntax is supported.

Test a branch filter safely in an isolated channel and scratch repo

Test in a throwaway channel against a throwaway repository, so a wrong guess never touches a channel your team relies on.

Create a private Slack channel such as #branch-filter-test and a scratch repo with a few branches, for example main and feature/test-one. Invite the GitHub app to the channel, then check what the channel is already subscribed to:

/github subscribe list features

Read the output before changing anything. Subscriptions are per channel and per repository, so a new test channel starts clean and your production channels are unaffected.

Now subscribe the scratch repo with the filter you want to check, for example commits:main. Push a harmless commit to main and note whether a message arrives. Then push a commit to feature/test-one and note whether one arrives. A correct commits:main filter should post for the first and stay quiet for the second. Change the filter, repeat, and write down each result.

Keep the test low-risk. Avoid force pushes and history rewrites, use a repo with no real secrets, and remove the test subscription when you're done:

/github unsubscribe OWNER/REPO commits

If your production channel also has other features on the same repository, look at the list output before and after you change a commits subscription. Check that the other features are still listed instead of assuming they were left alone.

Work out which event type actually posted

Before blaming a filter, identify what kind of message you're looking at. Only one of several event types obeys a commit branch filter.

A commit notification is the message produced by a push. It names the commits and the branch they landed on. That is the only kind a commits:BRANCH filter controls.

A pull request notification announces that a pull request was opened, closed, merged or similar. It belongs to the pulls feature and ignores your commit filter. A review notification, such as an approval or a requested change, belongs to the reviews feature. Comments belong to the comments feature, and issues to issues. The branches feature is something else again, described below.

A quick method: open the unexpected message and ask what it announces. If it announces a push with commits, check the branch filter. If it announces anything about a pull request, a review or a comment, run /github subscribe list features and see which of those features are on for that repo, then unsubscribe the one producing the noise. For example, /github unsubscribe OWNER/REPO reviews turns off review messages for that repository in that channel.

If the noise comes from labelled issues and pull requests rather than from commits, that's a different filter entirely. The GitHub Slack label filters guide covers it.

Why workflow notifications ignore your commit filter

Workflow notifications are controlled by the workflows feature, which has its own branch option. A commit filter has no effect on them.

The docs describe subscribing to Actions workflow runs and filtering them with a branch value. The format looks like this:

/github subscribe OWNER/REPO workflows:{branch:"BRANCH-NAME"}

Use this when you want failed or completed runs for one branch only, regardless of what your commits subscription says.

There is one trap worth knowing. A workflow that runs on a pull request from feature/login into main is matched against main. If you filter workflows to feature/login, you won't see it.

So a channel can have commits:main and still receive workflow messages about other branches, because those two settings don't know about each other. Set each one on purpose. For a walkthrough of getting failure alerts working end to end, see GitHub Actions Slack notifications on workflow failure.

What the branches event really does, and what the official filters don't cover

The branches event is not a filter. It reports branch creation and deletion. Subscribing to it tells your channel when a branch appears or disappears, and it says nothing about which branches' commits you see.

People sometimes enable it hoping it will limit notifications to certain branches, then wonder why nothing changed. If you see messages about a branch being created or deleted, that is this feature working as designed.

It also helps to be clear about what the official branch filters leave out. They give you no branch filtering for pull requests or reviews. Label filters exist for issues and pull requests, but they match on labels, not branch names. And the documentation has no failure-only option inside the filter syntax itself, which is why the workflow setup above is a separate piece of configuration.

If your real goal is fewer messages about pull requests, a branch filter is the wrong tool, and no combination of commits options will get you there. The next section covers the alternative.

Keeping one card per PR when branch filters are the wrong tool

If the noise you want to cut is pull request activity rather than commits, change how pull requests are presented. Searching for a filter that doesn't exist won't help.

The official app supports threading and updating the parent message, and it supports scheduled reminders, so first check whether those settings already solve it for you. Where a team wants a pull request or merge request to live as one updating card, MergeMe provides that for GitHub.com, GitLab.com and self-hosted GitLab in one Slack workspace. Branch-filtering behavior is not established here. Its verified scope is one updating card per PR/MR.

For related checks on missing or surprising PR messages, see GitHub Slack review comments not showing and GitHub draft PR Slack alerts.

Match the filter to the event, then test it in a scratch channel

A branch filter does one job: it limits commit notifications. Every other surprise in your channel comes from a different feature with its own settings. Run /github subscribe list features, identify the event type behind the noisy message, and prove each fix in an isolated channel against a scratch repo before touching production. If the real problem is pull request clutter, try MergeMe on one channel and see one updating card per pull request in place of the stream.

FAQs

Does commits:main filter pull request notifications in the GitHub Slack app?

No. The commits:main option scopes commit notifications only. Pull request, review, comment and issue messages come from separate features and are not affected by a commit branch filter. Run /github subscribe list features to see which features are on, then unsubscribe the one producing the unwanted messages.

How do I get GitHub Slack notifications for commits on all branches?

Subscribe with the wildcard option: /github subscribe OWNER/REPO commits:*. By default only the default branch is covered. The older commits:all form is closing down, with existing configurations continuing until updated, so use commits:* for new setups.

How do I filter GitHub Actions workflow notifications by branch in Slack?

Use the workflows feature with its own branch option: /github subscribe OWNER/REPO workflows:{branch:"BRANCH-NAME"}. This is separate from commit filters. For pull request workflows, the branch matched is the pull request's target branch, not the source branch.

Why does my GitHub Slack channel still get messages from other branches?

The message is probably not a commit notification. Pull requests, reviews, workflows and branch creation events each use their own feature and ignore commits:BRANCH. Check the message type, list the channel's features, and adjust the one responsible. MergeMe can instead show each pull request as one updating card.