Description of the problem:
I have a problem with starting the post-receive
hook automatically in the git repository.
After made push from the local to the remote repository, hook post-receive
just doesn’t execute.
Steps that I did:
- I create a (
non-bare
) repository on the local machine and create several commits - I create a repository on the remote machine (
bare
), create apost-receive
hook there and set it to chmod to 755 - On the local machine i add a remote repository (git remote add …..)
- I make a push that runs correctly
- Hook, unfortunately, does not fire
My environments:
- Local machine:
GIT 2.25.0.windows.1
@Win10 (1909)
- Remote machine:
GIT 2.25.0
@Debian 8.11 (jessie)
Content of post-receive file at remote machine:
#!/bin/sh
git --work-tree=/home/xxxxxx/xxxxxx/public_html/prod --git-dir=/home/xxxxxx/xxxxxx/dev.git checkout -f
- Note: When I run this code directly from the ssh console, it works fine
Other SO solutions?:
Yes, I’ve seen a lot, but none solve my problem.
I’ve seen some answers with “unset GIT_DIR” advice, but I’m afraid it has nothing to do with it, because even just the echo test > log.txt
does not work in post-receive
. It looks like post-receive
can’t be started?
2
Answers
Ok, I've found what the problem was - the partition on the host is mounted as
noexec
. If so, the hooks cannot work.This is for security reasons. It's typical situation on shared hosting.
My alternative solution:
We can create a git alias where you can run a bash script with ssh logging and run the git command directly on the server
How to do it?
In the local repository configuration file we add an alias:
(as you can see in the example, this alias will launch the hook.sh file)
Now we create a hook.sh file with git commands
And now we just have to use the
git run
commandNote: This is just a simple example. You have to test it on your envoirment!
I know there is already an accepted response, but seems the issue comes ’cause we are trying to run with bash instead of shell I change the post-receive hooks to the following: