Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 :)

share|improve this question
2  
see this and this post. –  harish.venkat Jan 13 '13 at 18:22
add comment

1 Answer

up vote 1 down vote accepted

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
share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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