Skip to content

Deleting merged branches

ernolf edited this page Aug 3, 2026 · 1 revision

🧹 Automatically deleting merged branches

A merged pull request leaves its source branch — the head branch — behind. Nothing removes it on its own, so over time a repository collects a long list of stale branches: your own feature branches, and the ncmake/… branches ncmake opens for you (make version releases on ncmake/release/x.y.z, the COMMIT/PR flags and the workflow updater on ncmake/ci/…).

GitHub has a single repository setting that cleans them up: it deletes each head branch the moment its pull request is merged. This is a general GitHub feature, not an ncmake one — it applies to every branch merged through a pull request — but ncmake apps benefit from it, which is why it is documented here.

Tip

TL;DRSettings → General → Pull Requests → tick "Automatically delete head branches". From then on every branch merged through a pull request is removed automatically. Nothing else is touched, and a deleted branch can be restored from its pull request.

⚙️ Turning it on

  1. Open the repository's Settings tab.
  2. On General (the default page), scroll to the Pull Requests section.
  3. Tick Automatically delete head branches.

That is the whole setup. It takes effect immediately and needs no workflow, token or permission of its own.

🎯 What it deletes, and what it does not

It deletes only the head branch of a pull request, and only once that pull request is merged. Concretely:

  • The base branch of the merge (main) is never touched — only the branch that was merged into it.
  • A branch is left alone as long as it still has another open pull request; it is removed only when no open PR points at it any more.
  • Only branches in this repository are affected. A pull request opened from a fork never has the fork's branch deleted.
  • Branches that were never opened as a pull request are outside its scope entirely — it is a merge-time cleanup, nothing more.

♻️ Restoring a branch

Deletion is not final. Every merged pull request keeps a Restore branch button on its page, so a branch removed by mistake — or one you want back to keep working on — is one click away, with its commits intact.

🔁 One repository at a time

The setting lives on the repository, so it is enabled per repository; a new ncmake app does not inherit it. Turn it on once in each repo where you want merged branches cleaned up.

Note

ncmake also ships a branch-cleanup.yml workflow that does the same thing from inside the repository, so the cleanup travels with the app through make workflows-install even where this setting has not been enabled. Running both is harmless — whichever removes the branch first wins, and the other is a quiet no-op.

Clone this wiki locally