简体   繁体   English

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

[英]I can't delete a remote master branch on git

I need to delete a master branch, but it's proving to be hard.我需要删除一个主分支,但事实证明这很困难。 I just want to clean that branch out and start new.我只想清理那个分支并开始新的。 I am deleting from the dev branch.我正在从 dev 分支中删除。 I want master on GitHub to be clean.我希望 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'

How do I quite simply start my master with a fresh slate?我如何简单地用新的石板开始我的主人?

As explained in "Deleting your master branch " by Matthew Brett, you need to change your GitHub repo default branch .正如 Matthew Brett 在“删除您的主分支”中所述,您需要更改您的 GitHub 存储库默认分支

You need to go to the GitHub page for your forked repository, and click on the “Settings” button.您需要转到分叉存储库的 GitHub 页面,然后单击“设置”按钮。

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

Or, since 2012, you can delete that same branch directly on GitHub :或者,自 2012 年以来,您可以直接在 GitHub 上删除相同的分支

GitHub 删除

That was announced in Sept. 2013 , a year after I initially wrote that answer.这是在 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 .对于文档修复、错别字等小更改,或者如果您只是一个行走的软件编译器,您可以在浏览器中完成很多工作,而无需将整个存储库克隆到您的计算机


Note: for BitBucket, Tum reports in the comments :注意:对于 BitBucket, Tum 在评论中报告:

About the same for Bitbucket Bitbucket 大致相同

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

To answer the question literally (since GitHub is not in the question title), also be aware of this post over on superuser.要从字面上回答这个问题(因为 GitHub 不在问题标题中),还要注意这篇关于超级用户的帖子 EDIT: Answer copied here in relevant part, slightly modified for clarity in square brackets:编辑:在相关部分复制这里的答案,为了清楚起见在方括号中稍作修改:

You're getting rejected because you're trying to delete the branch that your origin has currently "checked out".你被拒绝是因为你试图删除你的源当前“签出”的分支。

If you have direct access to the repo, you can just open up a shell [in the bare repo] directory and use good old git branch to see what branch origin is currently on.如果您可以直接访问 repo,您​​只需打开一个 shell [in the bare repo] 目录并使用旧的git branch来查看当前所在的分支原点。 To change it to another branch, you have to use git symbolic-ref HEAD refs/heads/another-branch .要将其更改为另一个分支,您必须使用git symbolic-ref HEAD refs/heads/another-branch

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

在 git bash 上输入这个命令行,一切都会被修复它对我rm -rf .git

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM