Delete all branches except master branch
- Your all local branch will be deleted except main or master branch branch
- This command do not affect the remote server
Delete all branches except master 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