3

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?

Alessio Gaeta
  • 5,670
  • 1
  • 16
  • 26
nizg
  • 31
  • 1
  • Have you get the answer which help you solve the problem? If yes, you can mark it as answer. And it will help others who have similar question. – Marina Liu Jun 29 '17 at 08:47

2 Answers2

2

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

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.

Marina Liu
  • 36,876
  • 5
  • 61
  • 74