Created a warehouse in the /home/work/
directory of Server A
/home/work/my-project.git
Clone /home/work/my-project.git
to the website root directory /home/www/
Configuredgit post-receive hook
#!/bin/bash
cd /home/www
env -i git pull
In this way, every time git push
, the code can be updated to the /home/www
directory of server A
If I clone /home/work/my-project.git
on Server B
to the directory /home/www/
. Is there any way to go to Server A
and Server B
to perform git pull
operations at the same time every time git push
is executed?
My current approach is to add a crontab scheduled task
on server B
, and execute it in the /home/www/
directory every minute git pull
, although this can also achieve the effect of automatic git push
, but there is also a time difference.
Do you have any better practices?
If
服务器A
能通过ssh访问服务器B
, you can add a line in git post-receive hookAfter each git push, server A will clone /home/work/my-project.git to the website root directory /home/www/, and at the same time, it will synchronize /home/www/ to server B’s /home through rsync
/www/