我已经解决了一些合并冲突,已提交然后尝试推送更改,并收到以下错误:

c:\Program Files (x86)\Git\bin\git.exe push --recurse-submodules=check "origin" master:master
Done
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'.
To C:/Development/GIT_Repo/Project
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'C:/Development/GIT_Repo/Project'

有谁知道是什么原因导致此错误?

最佳答案

原因:您正在推向非裸存储库

存储库有两种类型:bare and non-bare

裸存储库没有工作副本,您可以推送到它们。这些就是您在Github中获得的存储库类型!如果要创建一个裸仓库,可以使用

git init --bare

因此,简而言之,不能推送到非裸存储库(编辑:好吧,您不能推送到存储库的当前 checkout 分支。对于裸存储库,您可以推送到任何分支,因为尽管可能,但将其推送到非裸存储库并不常见)。您可以做的是从另一个存储库中获取并合并。这就是您在Github中可以看到的pull request的工作方式。您要求他们从您身边拉开,并且不要强行推入他们。

更新:感谢VonC在最新的git版本(当前为2.3.0)pushing to the checked out branch of a non-bare repository is possible中指出这一点。但是,您仍然无法推入肮脏的工作树,无论如何这都不是安全的操作。

07-24 12:54