正在删除远程主分支,由于是当前分支而被拒绝

如何从 GitHub/Bitbucket 中删除远程主分支?

我在努力:

# 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://git@bitbucket.org/user/reponame.git
! [remote rejected] master (deletion of the current branch prohibited)
error: failed to push some refs to 'ssh://git@bitbucket.org/user/reponame.git'

我也尽力了

git push bb :master

但这一切都不起作用。

78338 次浏览

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.

I did it :

  1. create a new branch.

  2. change it to main branch ( need refresh )

  3. remove master

in BitBucket goto repository details then Advanced then change main branch

enter image description here

then you can delete master from branches in main menu

then you can create master again from your one of branches then reconfigure Master branch as master