Delete all branches except master or main branch


















To delete all branches in your Git repository except master, simply issue the following command:

$ git branch | grep -v "master" | xargs git branch -D

If you want to delete branches such as master-prod, master-test or master-ui, you can adjust the RegEx used by the grep as follows:

$ git branch | grep -v " master$" | xargs git branch -D



Remove all Git branches but main
=======
To delete all branches in Git except main, simply replace the grep for master with a grep for main:

$ git branch | grep -v "main" | xargs git branch -D
$ git branch | grep -v " main$" | xargs git branch -D

Comments

Popular Posts

This is a SAMPLE TESTING MESSAGE sent through Cell Broadcasting System by Department of Telecommunication

Google doodle celebrates Colombia Independence Day 2023

Here's a comparison of PHP and Python syntax in a table format