如何在 Git 中删除 origin/master

如何在 Git 中删除 origin/master

我无法origin/master从我的服务器中删除。不知道为什么。

我的终端的屏幕截图

错误信息如下

remote: error: By default, deleting the current branch is denied, because the next
remote: error: 'git clone' won't result in any file checked out, causing confusion.
remote: error: 
remote: error: You can set 'receive.denyDeleteCurrent' configuration variable to
remote: error: 'warn' or 'ignore' in the remote repository to allow deleting the
remote: error: current branch, with or without a warning message.
remote: error: 
remote: error: To squelch this message, you can set it to 'refuse'.
remote: error: refusing to delete the current branch: refs/heads/master
To [email protected]:/export/home/a/elabshare/git/ID-check.git
 ! [remote rejected] master (deletion of the current branch prohibited)
error: failed to push some refs to '[email protected]:/export/home/a/elabshare/git/ID-check.git'

不,我是不是使用Github

答案1

有趣的事实:即使是在遥远的地方,存储库位于分支上。您被拒绝是因为您尝试删除您的源当前已“签出”的分支。

如果您有对 repo 的直接文件系统访问权限:

  1. 您只需打开一个 shell 进入裸仓库目录,然后使用 good oldgit branch查看当前分支来源(如果有;见下文)。要将其更改为另一个分支,您必须使用git symbolic-ref HEAD refs/heads/<another_branch>

  2. 在某些不寻常的情况下,包括默认分支被重命名时,repo 没有当前的“已签出”默认分支。在这种情况下,git branch | grep '^*'从裸 repo 目录运行将不会打印任何内容(默认分支*在默认分支名称左侧有一个),您可以运行上述git symbolic-ref ...命令来选择默认分支。(此外:git branch <new_branch>如果需要,您可以运行以创建一个新的分支,但必须先选择默认/当前分支。)

如果你正在使用 Github 或 Gitorious 之类的服务,则必须使用该工具提供的 UI 进行更改(请参阅这个答案了解如何在常用工具中执行此操作)。

答案2

除了从服务器中实际删除 master 之外,您还可以像这样替换它:

git push origin otherbranch:master -f

这将用 otherbranch 的内容替换 master,但它在远程仍将被称为 master。然后您可以在本地将 master 签出为 master。

相关内容