How to Clean Up Old Branches in GitHub

In this step by step guide you can find how to quickly find, compare and delete old branches in GitHub. The large number of branches can cause confusion and conflicts. Let's see how to clean the mess in GitHub by using the site's UI.

The process works for remote and local branches(which are added to GitHub).

Step 1: Open the GitHub project

Let's start by opening the project in GitHub:

Softhints Python Pandas Examples

Step 2: Open Branches Interface

Next step is to open all branches in GitHub interface by clicking on branches (as shown on the image below):

Step 3: Quick review of branches

The branches are separated in 4 categories:

  • Default branch - usually is the master
  • Your branches - branches created from you
  • Active branches - branches which are close to default branch or recently updated
  • Stale branches - branches without recent modifications

We are interested mainly in Stale branches

From the picture above we can conclude that:

  • testX is old branch which is behind master 65 commits
  • development is new branch which is ahead 1 commit of master

Step 4: Compare branch to master

Let's compare branch development with master in order to find what is the commit which is ahead of the master. Click on development:

Then click on compare button:

After verifying the changes we can create Pull Request if needed:

Step 5: Delete old/stale GitHub branches

From step 3 we find out that branch testX is empty and behind master - 65 commits. This is called a stale branch and probably is not needed anymore. In order to delete such branch you can click on the recycle bin next to it:

Resources