git - 我无法删除 git 上的远程主分支

标签 git github

我需要删除一个主分支,但事实证明这很难。我只想清理那个分支并开始新的。我正在从开发分支中删除。我希望 GitHub 上的 master 是干净的。

 # 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 在“Deleting your master branch”中所述,您需要更改 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):

git push origin :master

或者,自 2012 年以来,您可以 delete that same branch directly on GitHub :

GitHub deletion

那是 announced in Sept. 2013 ,在我最初写下那个答案的一年后。

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.


注意:对于 BitBucket,Tum报道 in the comments :

About the same for Bitbucket

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

关于git - 我无法删除 git 上的远程主分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12208751/

相关文章:

git - 如何让 Jenkins 不清理 git 工作区

git - 我如何要求(或敦促)git 提交者提供相关的作者信息?

Vim,缩进不保存

git - 在 GitHub 上更新 pull 请求后如何恢复审查过程?

java - Git Hub Actions 使用 Maven 对其他存储库的私有(private)包注册表进行身份验证

git - 当上游存在更改时,为什么 git status show branch 是最新的?

git - 是否可以在没有 API 或其他服务器的情况下使用 git lfs?

Gitlab升级: getting 500 error on certain pages

linux - Git init 仍然给我 master 而不是我配置中的默认分支名称(main)

android - GitHub项目未引入Android Studio