Git学习之常见错误 git push 失败

时间:2022-05-22 07:07:09

Git学习之常见错误 git push 失败


问题描述:

git push
Counting objects: , done.
Delta compression using up to threads.
Compressing objects: % (/), done.
Writing objects: % (/), bytes | 445.00 KiB/s, done.
Total (delta ), reused (delta )
remote: error: refusing to update checked out branch: refs/heads/5.1
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 t
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing int
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 som
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, se
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To ...

解决办法:

这是由于git默认拒绝了push操作,根据提示信息解决:

You can set 'receive.denyCurrentBranch' configuration variable to 'ignore' or 'warn' in the remote repository to allow pushing into...

进入项目的目录下的.git目录,编辑config文件:

增加一项配置:

[receive]
denyCurrentBranch = ignore

然后再次执行 git push,就可以成功了。

这是服务器上看不到刚提交的文件,需要执行:

git reset --hard

然后就OK了。

在初始化远程仓库时最好使用 git init --bare

而不要使用:git init