Mass Deleting Remote Git Branches
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”.
Scott Keck-Warren
Scott is the Director of Technology at WeCare Connect where he strives to provide solutions for his customers needs. He's the father of two and can be found most weekends working on projects around the house with his loving partner.
Top Posts
- Working With Soft Deletes in Laravel (By Example)
- Fixing CMake was unable to find a build program corresponding to "Unix Makefiles"
- Upgrading to Laravel 8.x
- Get The Count of the Number of Users in an AD Group
- Multiple Vagrant VMs in One Vagrantfile
- Fixing the "this is larger than GitHub's recommended maximum file size of 50.00 MB" error
- Changing the Directory Vagrant Stores the VMs In
- Accepting Android SDK Licenses From The OSX Command Line
- Fixing the 'Target class [config] does not exist' Error
- Using Rectangle to Manage MacOS Windows