Created a warehouse in the/home/work/
directory ofServer 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 timegit push
, the code can be updated to the/home/www
directory ofserver A
If I clone/home/work/my-project.git
onServer B
to the directory/home/www/
. Is there any way to go toServer A
andServer B
to performgit pull
operations at the same time every timegit push
is executed?
My current approach is to add acrontab scheduled task
onserver B
, and execute it in the/home/www/
directory every minutegit pull
, although this can also achieve the effect of automaticgit 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/