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:
non-bare
) repository on the local machine and create several commitsbare
), create a post-receive
hook there and set it to chmod to 755My environments:
GIT 2.25.0.windows.1
@ Win10 (1909)
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
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?
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.
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
In the local repository configuration file we add an alias:
[alias]
run = "!sh ./hook.sh"
(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
#!/bin/bash
ssh user@host -p [port] 'bash -s' <<-EOF
git --work-tree=/home/xxxxxx/xxxxxx/public_html/prod --git-dir=/home/xxxxxx/xxxxxx/dev.git checkout -f
exit
EOF
And now we just have to use the git run
command
Note: This is just a simple example. You have to test it on your envoirment!