1

I want to be able to push a repository to Github at midnight, every night. I know that Github isn't a back-up service, and, in no way am I expecting it to be this - I just want the best up-to-date version on Github and this works for me, and, my team. What I was thinking is this:

  • Creating a Bash script that pushes the repository to Github normally

  • In Crontab, execute the script at midnight every day of the week.

Would this be the best method to use? If so, this seems easy enough to do.

My next problem :) I want an email to be sent to me, after the repository has been pushed, so it would just send an email saying: "Repository Pushed.. Ok" or if there was a problem, it would alert me to this. Is this possible? If so, could anyone please provide some examples of how to do this.

Hope someone can help :)

1

As the links described as harish.venkat

Create a script /path_to_script, which would add new file, commit and push.

#!/bin/sh
cd /location/of/clone

git add *
if [[ $? != 0 ]] then 
   mail -s "add failed" someone@some.com
   exit 1
fi

git commit -a -m "commit message, to avoid being prompted interactively"
if [[ $? != 0 ]] then 
   mail -s "commit failed" someone@some.com
   exit 1
fi

git push
if [[ $? != 0 ]] then 
   mail -s "push failed" someone@some.com
   exit 1
fi

mail -s "push ok" someone@some.com

Change the script to executable,

chmod a+x /path_to_script

Use crontab -e and add below line

 # run every night at 03:00
 0 3 * * * /path_to_script
  • Thank you so much! This is actually what I need. Is it possible to have multiple .git repositories updated? E.g. if I had a folder called "Repositories" on the server which contained multiple .git repositories update everynight? If that makes sense.. – Phorce Jan 16 '13 at 12:01
  • Why not? You can setup anther scripte with updated /location/of/clone. – neo Jan 16 '13 at 14:12
  • Does this imply that for each of the repositories I have to create a new script? – Phorce Jan 16 '13 at 14:15
  • If you are novice in shell scripting, it would be better to setup a new script. – neo Jan 16 '13 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.