GIT 1.9 - 远程: 错误: 'receive.denyCurrentBranch'

3

我在使用Git 1.9时遇到了错误。
当我尝试“git push”时,出现以下错误:

remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.

因此,我的第一步是在这个论坛上阅读很多帖子,并尝试从谷歌中找到一些结果。可惜我发现没有一个适用于我的情况。

我正在使用Linux x86,并安装了Git 1.9。
我可以从服务器上"git clone"一个仓库并在其中工作。
例如,我在里面"touch testfile"来创建一个新文件。 现在我将"git commit"这个文件。
完成这个步骤后我 "git push",然后出现了错误代码。

我在其他文章中发现问题已经在Git 2.3中解决。 改变存储库配置文件中的"receive.denyCurrentBranch"值应该有所帮助。 有用的值应该是: refuse, updateInsteadignore

我尝试了所有这些值,但错误始终相同。

服务器上的配置值为:

[receive]
        denyCurrentBranch = refuse

以及 "git branch" 命令

*master

在客户端上,"git status" 是这样的:
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

因此,该错误可能随时出现,我目前不知道如何修复它。
我该如何避免这个错误提示?


你是否已经得到了帮助你解决问题的答案?如果是,你可以将其标记为答案。这将有助于其他有类似问题的人。 - Marina Liu
2个回答

2

0

正如 git 提示信息所述,“receive.denyCurrentBranch” 不被推荐使用。

通常我们使用 git 进行版本控制,有远程仓库和本地仓库之分。而远程仓库是真正进行版本控制的地方。通常情况下,远程仓库是裸仓库。

因此,建议的方法是将远程仓库在服务器上转换为裸仓库,并将其视为远程仓库,方法是通过 git clone <URL of repo> --bare 命令进行克隆,然后将其作为远程仓库进行操作。

现在,您可以克隆上述裸仓库并对其进行提交/推送。


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