Make sure your script is executable (in your remote_repo.git/hooks
)... and executed: for that, a simple echo "test" would be enough.
Then, when doing a git pull
, specify the work-tree and git-dir.
#!/bin/bash
cd "/home/servers/a"
echo "pulling in $(pwd)"
git --work-tree=/home/servers/a --git-dir=/home/servers/a/.git pull
No need for exit
.
The pull should not need a password, since the remote origin for that repo should be a relative path to the repo you just pushed to:
cd "/home/servers/a"
git remote -v
You should see /path/to/remote_repo.git
.
For paths managed by root, a possible solution is, in the hooks file, to use sudo git --work-tree=/home/servers/a --git-dir=/home/servers/a/.git pull
, after modifying /etc/sudoers
with:
dev ALL=(ALL) NOPASSWD: git
(as described in "Allow certain guests to execute certain commands")
If git
is in root $PATH
, that will work.