当使用gitolite时如何重命名主分支

4

我正在使用gitolite进行git访问权限管理。

我想将主分支(master)重命名为生产(production)。

我在gitolite中对该仓库具有RW+权限。

我使用以下命令在本地重命名分支:

git branch -m master production

然后,我想删除远程主分支,但是出现了以下错误:

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 gitolite@virgo:/puppeteer
 ! [remote rejected] master (deletion of the current branch prohibited)

我该如何在远程仓库上删除主分支(master branch)呢?
3个回答

1
问题是为什么要删除主分支。创建新的分支并将其推送到远程服务器要简单得多。
git checkout master
git branch production
git checkout production
git push origin production

然后您就有了一个新的远程分支。

我不想在那个仓库中有一个名为master的分支,因为它将用于puppet环境,并且分支名称必须代表环境名称。简而言之,我想将主分支重命名为production,并使该分支表现得像是主分支。因此,当任何人克隆该仓库时,他的主分支将是production。 - simonC
您不需要重命名分支。从主分支创建一个新的分支并将其推送。之后删除主分支。 - René Höhle
这正是我所做的...但由于提到的错误,我无法删除远程主分支,如果我正在使用gitolite管理远程存储库,我该如何设置receive.denyDeleteCurrent以忽略它? - simonC
这是一个老问题,但我遇到了完全相同的问题(使用puppet的repo),我唯一能找到的解决方案就是删除整个远程repo并重新推送它。 - yakatz

0

我无法评论gaige的答案,所以我将其作为答案添加,但是我不得不使用refs/heads/production(请注意heads中的s),因为这是我的Git存储库中引用的路径。在gaige链接的下面有另一个答案也使用了heads,而当前的Git文档也使用了heads


0

我知道这个问题已经超过6年了,但是答案是你不想在没有告诉git服务器未来有人克隆该分支时删除默认分支。

关于gitolite的说明可以参考答案

请注意,您需要启用symbolic-ref命令才能通过将其添加到您服务器上git用户的.gitolite.rc文件的命令列表中远程执行此操作。

启用后,您应该能够运行

ssh <gituser@yourserver> symbolic-ref puppeteer HEAD refs/heads/production

要更改默认分支,然后您应该能够删除旧的master分支。


根据@LaomaiWeng的评论进行更新,我漏掉了一个“s”


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接