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:

git branch -vl | grep "\[gone\]"
add-IAM 842affb [gone] renamed
fix-module 6ba98ba [gone] changed order of statements
fixed-accounts-ssm-keys 93d438c [gone] Fixed SSM parameter names for accounts (stage)
fixed-accounts-ssm-param-name d7083d2 [gone] fixes
repos-service-account-annotation 16cf128 [gone] Added actual updated-deploy-bot-role c879175 [gone] added replicasets into deploy-bot

Then you can delete all local branches:

git fetch -anpt && git branch -D $(git branch -vl | grep "\[gone\]" | awk '{print $1}')




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