GIT 1.9 - remote: error: 'receive.denyCurrentBranch'

匿名 (未验证) 提交于 2019-12-03 07:36:14

问题:

I have an error using Git 1.9.
When I try to "git push" I receive the following error:

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'. 

So, my first step was to read a lot here in this forum and tried to find some results from google. Sadly all I found was not working in my case.

I am working on Linux x86 and installed Git 1.9.
I can "git clone" one repository from my server and work in it.
For example I "touch testfile" in it to create a new file. Now I will "git commit" this file.
After this step I "git push" it and then I get the error code.

I found in other article's that the problem is solved in git 2.3 And that it should be helpful to change the value from "receive.denyCurrentBranch" in the config file from the repository. Helpful values should be: refuse, updateInstead and ignore

I tried all of them and the error will be always the same.

On Server the config value ist:

[receive]         denyCurrentBranch = refuse 

and the "git branch"

*master 

On client the "git status" is:

On branch master Your branch is ahead of 'origin/master' by 1 commit.   (use "git push" to publish your local commits) 

So, the error will appear any time, I do not really know how to fix it yet.
How can I avoid that error message?

回答1:

The general best practice would be to create on your server a bare repo (git init --bare, or convert your existing repo to a bare one), clone it, add and commit new files and then push.
That push would not have the error message you describe.

Note that any feature (2.3 receive.denyCurrentBranch updateInstead, or 2.4 push-to-deploy) allowing to push to a non-bare repo are not present in a Git 1.9.
You should be able to install the latest Git 2.13 from the right ppa.



回答2:

As the git message hint you, 'receive.denyCurrentBranch' is not recommended.

We usually version control by git with remote repo and local repo. And the remote the repo is the place where git really version controlled. Usually the remote repo is bare.

So the recommend method is convert the remote repo as bare in your server and treat it as remote repo by git clone <URL of repo> --bare, now work for it as remote repo.

Now you can clone the above bare repo and commit/push to it.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!