关于github:我无法在git上删除远程主分支

I can't delete a remote master branch on git

我需要删除一个主分支,但这很难。我只想把那家分店清理干净,重新开业。我正在从dev分支中删除。我希望Github上的主人干净。

1
2
3
4
5
 # git push origin --delete master

> To https://github.com/mymasterb.git  ! [remote rejected] master
> (deletion of the current branch prohibited) error: failed to push some
> refs to 'https://github.com/mymaster.git'

我该如何简单地用新的石板开始我的主人?


如Matthew Brett在"删除主分支"中所述,您需要更改Github回购默认分支。

You need to go to the GitHub page for your forked repository, and click on the"Settings" button.

Click on the"Branches" tab on the left hand side. There’s a"Default branch" dropdown list near the top of the screen.

From there, select placeholder (where placeholder is the dummy name for your new default branch).

Confirm that you want to change your default branch.

Now you can do (from the command line):

1
git push origin :master

或者,从2012年起,您可以直接在Github上删除同一个分支:

GitHub deletion

这是在2013年9月宣布的,那是在我最初写下答案的一年之后。

For small changes like documentation fixes, typos, or if you’re just a walking software compiler, you can get a lot done in your browser without needing to clone the entire repository to your computer.

注:对于bitback,tum在注释中报告:

About the same for Bitbucket

1
Repo -> Settings -> Repository details -> Main branch


最快的方法是将默认分支从主分支切换到另一个主分支,您可以从Web界面中删除主分支。