KillMe
KillMe

Reputation: 194

Is there a way to auto update my github repo?

I have a website running on cloud server. Can I link the related files to my github repository. So whenever I make any changes to my website, it get auto updated in my github repository?

Upvotes: 1

Views: 10636

Answers (1)

josephting
josephting

Reputation: 2665

Assuming you have your cloud server running an OS that support bash script, add this file to your repository.

Let's say your files are located in /home/username/server and we name the file below /home/username/server/AUTOUPDATE.

#!/usr/bin/env bash

cd $(dirname ${BASH_SOURCE[0]})

if [[ -n $(git status -s) ]]; then
    echo "Changes found. Pushing changes..."
    git add -A && git commit -m 'update' && git push
else
    echo "No changes found. Skip pushing."
fi

Then, add a scheduled task like crontab to run this script as frequent as you want your github to be updated. It will check if there is any changes first and only commit and push all changes if there is any changes.

This will run every the script every second.

*/60 * * * * /home/username/server/AUTOUPDATE

Don't forget to give this file execute permission with chmod +x /home/username/server/AUTOUPDATE

This will always push the changes with the commit message of "update".

Upvotes: 5

Related Questions