I would like to sync my git repository on my server to my local webserver. All the guides I read caused different errors and now I'm really desperate. I'm sorry if you already read this question a hundred times, but I still don't get it -.-
The cron should do this commands every minute or less with the user "cron":
cd /srv/www/htdocs/my_project
git pull origin
(git fetch) <-- not mandatory
These commands work fine when I input them manually. (except I have to enter the user password every time)
In this question I got some informations, but I always get an error when I try them myself.
My cron should look like this then:
* * * * * su -s /bin/sh cron -c 'cd /srv/www/htdocs/my_project && /usr/local/bin/git pull origin master'
I executed this on my PuTTY, which answered me: -bash: bin: command not found
My next try was:
crontab * * * * * su -s /bin/sh cron -c 'cd /srv/www/htdocs/my_project && /usr/local/bin/git pull origin master'
Error: crontab: invalid option -- 's'
Error: crontab: usage error: unrecognized option
I tried a lot more combinations (removing the su -s or removing the -c etc.) but it never worked as I wanted -.- Shouldn't I do this command on PuTTY?
Good to know: I'm a linux and GIT beginner, started working with it yesterday and actually managed to do a lot til now. (^.^) So I would be happy to have an understandable explanation, in what I do wrong and what I have to do. It's confusing.
The easiest way to achieve what you want (have the git repository automatically deployed on your server) is by putting the git repository inside you webserver and using a hook to do a check out on push. How to this is described in this answer: Deploy a project using Git push
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With