<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Aman Anuragi</title>
    <description>The latest articles on DEV Community by Aman Anuragi (@mr-aman-anuragi).</description>
    <link>https://dev.to/mr-aman-anuragi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4270441%2Fde7195ac-2a7f-4d31-8779-32766b9345b8.jpg</url>
      <title>DEV Community: Aman Anuragi</title>
      <link>https://dev.to/mr-aman-anuragi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mr-aman-anuragi"/>
    <language>en</language>
    <item>
      <title>Delete merged Git branches automatically - without risking the ones you need</title>
      <dc:creator>Aman Anuragi</dc:creator>
      <pubDate>Sat, 28 Nov 2026 09:19:05 +0000</pubDate>
      <link>https://dev.to/mr-aman-anuragi/delete-merged-git-branches-automatically-without-risking-the-ones-you-need-2ggj</link>
      <guid>https://dev.to/mr-aman-anuragi/delete-merged-git-branches-automatically-without-risking-the-ones-you-need-2ggj</guid>
      <description>&lt;p&gt;Branches pile up. Ours went from a handful to 72 in a few weeks, most of them already merged.&lt;/p&gt;

&lt;p&gt;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 &lt;code&gt;staging&lt;/code&gt; or &lt;code&gt;develop&lt;/code&gt; after a release PR — and it never touches branches merged before you turned it on.&lt;/p&gt;

&lt;p&gt;So we built &lt;strong&gt;Safe Branch Cleanup&lt;/strong&gt;, a small GitHub Action that checks each branch first. It deletes a branch only when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;it had a merged pull request, and&lt;/li&gt;
&lt;li&gt;its latest commit is already in your base branch (squash and rebase merges included).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It never touches your default or base branch, protected branches, a keep list you choose, branches with an open pull request, work in progress, or pull requests closed without merging. Anything deleted can be restored from its pull request page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;Add one step to a workflow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;manthrix/safe-branch-cleanup@v1.0.0&lt;/span&gt;
  &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;keep-branches&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;staging, develop&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run it once in dry-run mode to see exactly what it would delete. On our own repo it took us from 72 branches to 2 — safely.&lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;GitHub Marketplace: &lt;a href="https://github.com/marketplace/actions/safe-branch-cleanup" rel="noopener noreferrer"&gt;https://github.com/marketplace/actions/safe-branch-cleanup&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Source (MIT, no dependencies): &lt;a href="https://github.com/manthrix/safe-branch-cleanup" rel="noopener noreferrer"&gt;https://github.com/manthrix/safe-branch-cleanup&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are a few "good first issue" tasks if you'd like to contribute. Feedback welcome — especially edge cases we haven't thought of.&lt;/p&gt;

</description>
      <category>github</category>
      <category>githubactions</category>
      <category>devops</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
