Git - remote: error: cannot run hooks/post-receive: No such file or directory

I get the error :

remote: error: cannot run hooks/post-receive: No such file or directory

When trying to push to remote. The post-receivce file exists in the correct location (testnew.git/hooks) and contains:

#!/bin/bash2
export GIT_DIR=/var/www/testnew/testnew/.git/
export GIT_WORK_TREE=/var/www/testnew/testnew/
cd /var/www/testnew/testnew/

echo "here we go..."
git fetch
git merge origin/master
git submodule update --init --recursive

I've tried setting permissions on post-receive using:

chmod a+x post-receive

But this gives same error. Setting permission to 755 removes the error , but the script does'nt run.

Answers


This would happen if the hooks/post-receive file exists, is marked executable, but cannot be executed. It cannot be executed, because the interpreter, /bin/bash2, either does not exist or is not executable.

Replace the /bin/bash2 with name of bash that does exist and is executable on the server.

(The reason the error looks like this is, that the operating system only returns the error status, "No such file or directory", but does not report which file does not exist. And the code that tried to execute it does not know that the system already read hooks/post-receive and was looking for /bin/bash2. All it knows is it tried to run hooks/post-receive, so that's what it prints).


In addition (for future reference and documentation on this question) if you were to run echo $SHELL in your shell you should see an expected result, in this case (based on the approved answer) you would expect /bin/bash as your result. But another possible problem can be an unseen carriage return.

Try running hooks/post-receive if you're still having issues, you may get a response like this:

-bash: hooks/post-receive: /bin/bash^M: bad interpreter: No such file or directory

The key here is the ^M that is proof that you are in fact getting an unexpected carriage return, otherwise if it had worked you would probably get a hanging response.

Fix that and it should fix your problem. The way to do that, use dos2unix, for example:

dos2unix .htaccess

It was caused by me forgetting to do git init first.


Need Your Help

C++ - char** argv vs. char* argv[]

c++ main arguments

What is the difference between char** argv and char* argv[]? in int main(int argc, char** argv) and int main(int argc, char* argv[])?

Compilers for Haskell

compiler-construction haskell ghc

AFAIK GHC is the most common compiler today, but I also see, that some other ompilers are available too. Is GHC really the best choice for all purposes or may I use something else instead? For inst...