Automatically delete git branch after merge to master

ton.yeung picture ton.yeung · Jan 23, 2013 · Viewed 21.5k times · Source

We will be attempting a work flow in github where every ticket is a branch off of master.
After the ticket is complete, the work is merged into staging where regression and integration tests are performed before it is merged into master.

A team lead brought up the issue of the old ticket branches after a merge will start to build up.

I found this script and want to know if this would work in our environment. We only want to delete branches that have been merged into master.

Answer

Karan Bansal picture Karan Bansal · Aug 2, 2019

Github has released a feature where anyone with admin permission to the repository can configure branches to get deleted automatically after pull requests are merged. Here are the steps -

  1. Navigate to main page of the repository and click on Settings.
  2. Under "Merge button", you can select or unselect "Automatically delete head branches" option.

This feature has been released by Github on July 31, 2019.