7

I use git to push commited changes to a repo that lies on a server. Now there is this Error:

$ git push -u origin master
fatal: bad config value for 'receive.denycurrentbranch' in ./config
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

What it looks like in the console Window

Now I suppose that this error might be due to some failures in the SSH connection. I use PuTTY to connect via SSH to my webserver. However, I'm still a noob and i don't know exactly how this works.

So what I've tried is that I genereated the private key online, downloaded it, translated it into PPK-Format and put it in the authentication tab in PuTTY. When i log in via PuTTY i have to put in key passphrase and then it manages to connect without error.

The error is only in git bash. So how do I fix it there? Do somehow need to tell Git to use PuTTY as my SSH agent (what is an SSH agent anyway?). Or is Git by default using OpenSSH from Windows 10?

I've also tried to use

$ eval $(ssh-agent -s)
$ ssh-add ~/.ssh/id_rsa

but I don't exactly know what it does. Does it just start the OpenSSH-Agent?

If someone could clear things up a bit for me i would be more than happy. I have been googling for about a day and while pieces slowly come together, I wasn't able to solve that particular problem. Thanks! :)

Update 19.7.19

The Problem is still not solved entirely. Yes, setting receive.denycurrentbranch to ignore or refuse on the server side makes the error disappear. I can push, however there are no files showing. Apparently, only commits are saved in the repo and not the files themselves. As I figured, I need the updateInstead option which allows for non-bare repos (repository with actual files instead of just commits) to exist, so that the server can take these files from the repo and deploy them in my public_html-folder.

My server git version is 2.19.1, which is seemingly higher than the 2.4.0 version which is required to interpret the updateInstead-Parameter. So it's still a mystery to me why this error appears.

I'm right now trying to install a new git version on my server just to see if that changes anything. However, I encountered a different problem there. Please visit this thread.

Community
  • 1
  • 1
glades
  • 3,778
  • 1
  • 12
  • 34
  • Possible duplicate of [Git receive.denyCurrentBranch updateInstead fails](https://stackoverflow.com/questions/32643065/git-receive-denycurrentbranch-updateinstead-fails) – phd Jul 11 '19 at 14:32
  • https://stackoverflow.com/search?q=%5Bgit%5D+fatal%3A+bad+config+value+for+receive.denycurrentbranch – phd Jul 11 '19 at 14:32
  • Just to be clear, `receive.denycurrentbranch` is a setting on the server side. It would serve no purpose on your PC. – VonC Jul 15 '19 at 14:44

6 Answers6

18

I know this is an old issue, but I have solved it and wanted to post the solution for others.

The issue appears to be that there are 2 git installations on your hosting provider. One is installed in \usr\bin and used by default. This one is probably 1.8.* or something earlier than 2.4. The other is installed in the cpanel app directory and is linked in your path. Because git doesn't run a full shell, the default 'old' version is used rather than the one that you get back from git version when you run in an ssh session . To fix this first look at the path of the git-receive-pack under your ssh session:

which git-receive-pack 

Than on your local machine update your remote config:

git config remote.<remote-name>.receivepack <receive-pack-path>

That should fix your problem.

Aaron Dalton
  • 181
  • 1
  • 3
9

For anyone who is using Cpannel and getting this error you may want to try this:

git push origin master -u --exec=/usr/local/cpanel/3rdparty/bin/git-receive-pack

Taken from Cpannel's Git page:

https://documentation.cpanel.net/display/CKB/Guide+to+Git+-+Host+Git+Repositories+on+a+cPanel+Account

Joe
  • 151
  • 2
  • 2
2

I've been setting up a git repository on Bluehost hosting. The git version there is 2.19.1. I've created the repo through cPanel. And I figured out the same problem with 'receive.denycurrentbranch'.

I've managed to fix the issue by editing git config files. They now look like

Global configuration (git config --global --edit)

[receive]
#       denyCurrentBranch = updateInstead
#       denyNonFastForwards = true

Local repo configuration (git config --edit)

[core]
        repositoryformatversion = 0
        filemode = true
        bare = true
        logallrefupdates = true
        symlinks = false
[receive]
#       denyCurrentBranch = updateInstead
[gc]
        auto = 0
2

I also got the same issue. When I run the command git --version it shows 2.24.1 but it wasn't accepting updateInstead as mentioned in the above question.

I did this to solve this issue:

  1. Run this command.
which git

It will give you the path of git.

Example output

/usr/local/cpanel/3rdparty/lib/path-bin/git
  1. Go to ~/.bashrc file and add this code to the bottom of the file
export PATH=/usr/local/cpanel/3rdparty/lib/path-bin:$PATH

*Note that I am not including git at the end of the path.

Hope this solves the issue.

AsDh
  • 86
  • 1
  • 4
0

The problem you're seeing is that you've set an invalid configuration value for the receive.denycurrentbranch option. It looks like from your console window that you have a version of Git that doesn't understand the refuse value (or you typed something like a non-breaking space in the value).

You should know that this value only applies to the server side. Setting it on the client side doesn't have any effect whatever. You should remove it from your config by editing the config (or .git/config, as appropriate) file and deleting the appropriate option, which should make pushes work again.

bk2204
  • 64,793
  • 6
  • 84
  • 100
  • ahh I must say that doesn't work with any value. I have tried `ignore, refuse, updateInstead` but neither of them works. Or do you mean i have to change the config file on the server side? – glades Jul 11 '19 at 14:22
  • The push problem you're having is due to a bad value on the client side; you must edit the client-side config file to remove the invalid setting. If you want the option you're setting to have any effect (other than producing an error) on your pushes, it must be set on the server side instead of the client side. – bk2204 Jul 11 '19 at 14:25
  • Thanks, but what option should i use instead of `refuse`? It was set to `updateInstead` at the start, but this didn't work either so i tried changing it. – glades Jul 11 '19 at 14:33
  • Don't set it on the client side at all (you can remove it with `git config --unset receive.denycurrentbranch`). Log into the server and set it only there (where `updateInstead` should be fine, provided you have a new enough Git). – bk2204 Jul 11 '19 at 14:47
  • 1
    IT WORKED. i set `receive.denycurrentbranch` on the server side to `ignore`. Because both, local and serverside git have versions less than 2.4. so the previous `updateInstead` value couldn't be interpreted by the server git. – glades Jul 11 '19 at 15:01
  • 1
    STILL NOT SOLVED entirely. Yes, setting `receive.denycurrentbranch` to `ignore` or `refuse` on the server side fixes the error. I can push. However as I figured, I need the `updateInstead` option which allows for non-bare repos (repository with actual files instead of just commits) to exist, so that the system can deploy my website from there. My server git version is 2.19.1, which is seemingly higher than the 2.4.0 version which is required to interpret the `updateInstead`. So what else could possibly be the problem? – glades Jul 17 '19 at 12:19
0

receive.denycurrentbranch to ignore will not solve problem it will create more problems later i suggest you to follow below steps

This will solve your problem for sure as i wasted my 5 hour in search for the same issue -

  1. First check the GIT VERSION on remote using ssh using command git --version In my case it was 2.19.1 which is this root cause for this problem.

  2. I suggest to create a new repo on cPanel before staring the below process, once you create new repo check following....

  3. Now make sure on remote config denyCurrentBranch = updateInstead below is my remote config screenshot, you can check remote config using command git config --edit when you inside remote repo directory My Live git config screenshot

  4. Now clone the cpanel repo on your local, and check your local git config file and make sure it has the tag [remote "origin"], if you can't find it use this command on your local git remote add origin ssh://username@website/home/username/reponame

  5. Now simply add any test file and commit the changes and push using below command and your remote repo will get updated 100% git push origin master -u --exec=/usr/local/cpanel/3rdparty/bin/git-receive-pack

Regards!