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

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'

有人知道是什么导致了这个错误吗?


当前回答

也许您的远程回购在您想要推送的分支中。您可以尝试在远程机器上签出另一个分支。我这样做了,这些错误消失了,我把成功推到我的远程回购。注意,我使用ssh连接我自己的服务器,而不是github.com。

其他回答

在另一篇文章中解释这个问题。 在我看来,更好的做法是:

对于远程服务器中的存储库:git branch -b work, work是一个专门用于远程服务器的工作分支。 将本地提交推到远程服务器,本地分支的名称(dev)应该与work不同,以避免混乱,现在git Push origin dev不会出现错误。 合并开发以在远程服务器中工作。git合并。

因为已经有一个现有的存储库正在运行

git config --bool core.bare true

在远程存储库上就足够了

从核心开始。裸露的文档

如果为true (bare = true),则假定存储库是空的,没有关联的工作目录。如果是这种情况,许多需要工作目录的命令将被禁用,例如git-add或git-merge(但您将能够推到它)。

在创建存储库时,git-clone或git-init会自动猜测该设置。默认情况下,存储库以“/”结尾。Git”被假设为非裸(bare = false),而所有其他存储库都被假设为裸(bare = true)。

我有这个错误,因为git回购(意外地)初始化两次在同一位置:第一次作为一个非裸回购和不久之后作为一个裸回购。因为.git文件夹仍然存在,所以git假定存储库是非裸的。删除.git文件夹和工作目录数据解决了这个问题。

CD到您在远程计算机上插入的repo/目录中,然后输入

$ git config core.bare true

正如在其他回答中提到的,您不能推到签出的分支。让我们从这里开始。

从远程服务器,让我们将远程存储库签入到一个临时分支。

git checkout -b temp

现在,我们可以从本地存储库推送到主分支。

git push

但这不是长久之计。未来的推动将带来同样的问题。为了一劳永逸地解决这个问题,您需要将远程存储库转换为裸存储库。从远程服务器输入:

git config core.bare true

现在你可以毫无问题地推到遥控器了。

以后,使用——bare选项创建远程存储库,如下所示:

git init --bare