Git Logo Git Logo from https://git-scm.com/downloads/logos

The other day at work I realized how many open branches we had in our Git repo that had been merged into the master branch but weren’t deleted from our BitBucket repo. I started looking for ways to quickly cleanup the branches without automating the process so I didn’t accidentally delete something that was still needed.

My initial search found that you can delete a remote branch using the following command:

git push origin --delete name-of-branch

My issue was that I needed to delete hundreds of of branches. Luckily you can specify multiple branches for this command like so:

git push origin --delete name-of-branch1 name-of-branch2 name-of-branch3 name-of-branch4

I was able to use git branch --merged to get a quick list of all the branches that had been merged into master and then I ran the command above on them once I verified they were all “old”.