简体   繁体   中英

How to update my server files from a git repo automatically everyday

I am a noob in these server related work. I am writing some PHP code in my local system and has been updating my repo in github regularly. Each time I want to test my application, I copy all the files from my local system onto my server through FTP and then do it. Now I want to know whether is there a way to automatically make the commits that I make to reflect in the files in the server. Is there a way to automatically make the server get the files from the repo periodically? (say, once everyday).

Can this be done other way, like when I make a push from my local machine, the repo gets updated and in turn the files on the server also get updated?

My Server Details: Apache 2.2.15, Architecture i686 with Linux Kernel 2.6.18-194.32.1.el5

Perhaps explore the git archive command, which you can use to get a zip file or similar of your code. You could then perhaps use a script to copy that to your (other) server?

git archive --format=zip --output=./src.zip HEAD

will create a zip file called src.zip from the HEAD of your repo

More info:

If you have cronjobs you can use them. First set up the repository on your server. Then you can set up the cronjob, choose a time in which it should be executed, and then in the cronjob execute the following command:

cd your/repository/folder; git pull master origin

除了cronjobs,您还可以使用post-receive钩子: http ://help.github.com/post-receive-hooks/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM