Deleting remote master branch, refused due to being the current branch

In the settings block on the options tap in the settings page (well, just click on the Settings tab on your GitHub repository page), you are able to change the default branch (you need to have the other default branch on GitHub as well).

Change default branch on GitHub

After you have done that, you are able to remove it:

$ git push bb :master

Note: for Bitbucket, you would change the default branch by accessing the settings of your repository, and changing the branch at the "Main branch" combo box.

Main branch on Bitbucket

Once the main branch is no longer master, then you can push and remove master.

MarsAndBack confirms in the comments this applies to GitHub as well.


In 2021:

  • go to Repository Settings
    Repository Settings menu item image
  • scroll down to Advanced
  • scroll down to Main Branch
  • choose the new branch from the dropdown

enter image description here

Then, run your git change command, eg git push bb --delete master

or, in my case, git push origin :master main

Note: You'll have to be the repository's administrator to make changes like this.