git - Still cannot push to non-bare repo after setting receive.denycurrentbranch=ignore

2.8k Views Asked by At

My setup is as follows:

I am running git version 2.3.2 (Apple Git-55) on my mac. This has a non-bare git repository sitting at ~/xyz.

Then I am running Windows 7 64bit using VMWare Fusion on the same mac. The VM has git 1.9.5, which is the latest git version for Windows. From the VM I can clone and pull from my mac's non-bare repo ~/xyz OK, but I cannot push to it. I have followed the suggestion here and set receive.denycurrentbranch=ignore on ~/xyz but still gives me the same error message:

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

I have also tried setting receive.denycurrentbranch=updateInstead but still the same error message.

I have restarted the computer after each instance of changing any git settings.

The directory ~/xyz is a shared directory to my VM, and I have ensured the VM has read/write access to it.

Please, anyone has any ideas?

2

There are 2 best solutions below

0
On

You need to run the command from the server where you are pushing the code not from the local repo system

git config --global receive.denyCurrentBranch ignore
2
On

First, the VM can use any version of Git it want, not just the old and obsolete msysgit 1.9.5 one: git for windows offers the latest 2.4.6.
No setup required, just uncompress PortableGit-2.4.6-5th-release-candidate-64-bit.7z.exe anywhere you want and add its bin folder to the %PATH%.

I have also tried setting receive.denycurrentbranch=updateInstead

That Git 2.3.0+ feature (see the release notes) has to be set on the server side, not the client.

If that is not convenient, the OP Jason L mentions in the comments the workaround of:

not pushing to the mac git repo from the VM, but instead pulling the VM git repo from the mac.