Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Delete merged Git branches automatically - without risking the ones you need

Branches pile up. Ours went from a handful to 72 in a few weeks, most of them already merged. GitHub has a built-in fix: "Automatically delete head branches". But it deletes a branch the moment its pull request merges. On repositories without branch protection, that includes long-lived branches like staging or develop after a release PR — and it never touches branches merged before you turned it…

Branches accumulate rapidly within projects. In a few weeks, a project went from a few branches to 72, many of which were already merged. GitHub offers a built-in feature: "Automatically delete head branches". However, this feature deletes a branch immediately after its pull request merges. On repositories without branch protection, this includes long-lived branches like staging or develop after a release pull request.

Importantly, it does not delete branches merged before the feature was activated. To address this issue, a team developed Safe Branch Cleanup, a GitHub Action. This tool checks each branch before deleting it. It only deletes a branch if it has a merged pull request and its latest commit is already in the base branch (including squash and rebase merges).

It never touches the default or base branch, protected branches, branches on a keep list, branches with open pull requests, work in progress, or pull requests closed without merging. Any deleted branches can be restored from their pull request page. To set up the tool, add one step to a workflow: use the manthrix/safe-branch-cleanup version 1.0.0, specifying the branches to keep.

Running the tool in dry-run mode allows you to see exactly what it would delete. After implementing it, the number of branches was reduced from 72 to 2. The tool is available on GitHub Marketplace and has a few "good first issue" tasks for contributors. Feedback is welcomed, particularly for edge cases that may have been overlooked.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

Tax-Free States Are the Address Fixture Nobody Tests

A surprising number of address forms treat "state" as decoration — a dropdown you pick from and never think about again. Then someone enters an address in Oregon, Delaware, New Hampshire or Montana…

  • Many address forms overlook tax-free states' significance.
  • Production bugs arise from assuming sales tax lines always exist.
  • Testing with tax-free state addresses prevents future regressions.

What Is WebSockets? Build a Real-Time Chat Server with Express, NestJS, and MongoDB

You send a chat message and wait. Nothing happens. You refresh the page, and there it is, three messages late. 😅 That's what happens when a "live" feature is built on plain HTTP alone.

  • WebSockets enable open communication between browser and server
  • Socket.IO built on top of WebSockets with extra features
  • Real-time updates improve user experience in chat apps

More from Saturday, 28 November 2026 →