Clean up local git branches

Photo by Yancy Min on Unsplash

If you are using a flow to create a new branch then after merge this branch deleted automatically when PR merged then you can have plenty of local branches that were deleted on “remote”. I needed to quickly delete all ‘gone’ branches locally. Sharing how do I do it quickly on daily basis.

The first step is to issue git fetch : git fetch -anpt

Then review what is gone:

Then you can delete all local branches:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Maxim

Principal Software Engineer at Docker, ex f5 Networks engineer. Opinions are mine