Created
October 25, 2016 00:14
-
-
Save jazlopez/3106944230c539ae83d9905d8f76534b to your computer and use it in GitHub Desktop.
Git pull inside root crontab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Git repository may not allow root to pull down updates | |
# Pull updates where $user is allowed to read/write remote. | |
# command line: | |
su -s /bin/sh $user -c 'cd /var/www/html/src && /usr/bin/git pull origin master' | |
# crontab (by executing sudo opens up root crontab) | |
sudo crontab -e | |
# every 1 minute pull changes (if any) | |
*/1 * * * * su -s /bin/sh $user -c 'cd /var/www/html/src && /usr/bin/git pull origin master' |
oh finally a smart guy who thinks like me.. thank you bro.
@RaulSofia @myalcin81 thank you folks
I changed it a bit like below;
* * * * * su -s /bin/sh my -c 'cd /mydir && /usr/bin/git fetch --all && /usr/bin/git reset --hard origin/master && /usr/bin/git pull origin master'
It was going to stuck on some changes like if you update a file in local, git pull would be aborted to not overwrite local changes, with the changes I did, now its overwrite, it always pull.
Also there are some tricky issues like if you have a untracked files in your local, it won't be updated. If you overwrite those, you should clean up first:
git clean -d -f .
@myalcin81 thank you for sharing your version.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jazlopez that's brazilian slang for "very cool"