Search code examples
gitgithubbitbucket

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


How do I delete a remote master branch from GitHub/Bitbucket?

I'm trying:

# git push bb --delete master
remote: bb/acl: user is allowed. accepted payload.[K
remote: error: refusing to delete the current branch: refs/heads/master[K
To ssh://[email protected]/user/reponame.git
 ! [remote rejected] master (deletion of the current branch prohibited)
error: failed to push some refs to 'ssh://[email protected]/user/reponame.git' 

Also I tried

git push bb :master

But all this does not work.


Solution

  • 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.