1. Andrew Hagedorn
  2. Articles
  3. Delete Local Git Branches

Delete Local Git Branches

Andrew Hagedorn, October 2020

This is an archive of the random commands I have found useful. You may or may not, but the next time I need them I will know where to find them.

My development workflow doesn't really necessitate that I clean up my local branches very often. I mostly ignore them until one day I do git branch and the result is taller than my terminal. Rather than think to hard about it, I instead immediately declare bankruptcy and run this command to delete all my local branches:

function deletebranches() { 
    git branch  | egrep -v "(^*)" | xargs git branch -d; 
}

An important thing to note is the -d. In its lower case form it will only delete local branches that are fully merged into its upstream branch. If you are really feeling bold you can instead use -D which will force delete all your local branches.

© 2024