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

时间:2017-06-07 07:34:44

标签: git github version-control

使用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”的值应该会有所帮助。 有用的值应为:refuseupdateInsteadignore

我尝试了所有这些,错误总是一样的。

在服务器上配置值ist:

[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)

所以,错误会随时出现,我还不知道如何修复它 如何避免该错误消息?

2 个答案:

答案 0 :(得分:1)

一般的最佳做法是在您的服务器上创建 bare repo git init --bareconvert your existing repo to a bare one),克隆它,添加和提交新文件然后推 该推送不会出现您描述的错误消息。

请注意,Git 1.9中不存在允许推送到非裸机的任何功能(2.3 receive.denyCurrentBranch updateInstead2.4 push-to-deploy)。 您应该可以安装latest Git 2.13 from the right ppa

答案 1 :(得分:0)

正如git消息提示你,不建议使用'receive.denyCurrentBranch'。

我们通常使用远程仓库和本地仓库通过git进行版本控制。而远程repo是git真正版本控制的地方。通常远程仓库是裸的。

所以建议的方法是将远程仓库转换为裸机服务器并将其视为远程仓库 git clone <URL of repo> --bare,现在作为远程仓库工作。

现在你可以克隆上面的裸仓库并提交/推送它。