Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm using git for the purposes of making a historical transcript of the changes made to my project. I understand it's not the ideal usage but it's the usage pattern I've chosen for various reasons which I won't get into for the sake of brevity.

How would I create a cron job that would commit the changes to the repository each day or week?

I'm using the latest version of git on Ubuntu 10.10.

share|improve this question

2 Answers 2

up vote 7 down vote accepted
0 20 * * 0 /path_to_script

That will run the command specified (replace /path_to_script') at 20:00 local time every Sunday. The syntax for cron jobs is fairly simple, and there's a slick tool that will help you create them without remembering the code positions.

In this case, the command should be a script that runs the commit for you. I think it would be easiest in your case to write a quick shell script to change to the clone directory and then run the commit. Create a file at ~/commit.sh and put this in it (replacing /location/of/clone, of course)


#!/bin/sh
cd /location/of/clone
git-commit -m "commit message, to avoid being prompted interactively"

Then chmod +x ~/commit.sh to make it executable, and have the cron job run that (referring to it by it's full path, rather than using ~).

share|improve this answer
    
Good answer. Keep in mind that the cronjob (obviously) only gets executed if your computer is running at the specified time (e.g. Sunday 20:00). –  pableu Mar 31 '11 at 7:35
    
how can i make it do the push to the server as well? –  Jason Apr 4 '11 at 23:53
    
Also, how do i make it add files that i've added –  Jason Apr 4 '11 at 23:56
    
Just add git-push to the script to have it push to the server as well. You can use the -a option to git-commit to have it automatically add all files that have been modified or deleted. –  jcrawfordor Apr 5 '11 at 22:29
    
Don't you want to add a -a to the commit command, so it will add automatically all the files that are already tracked to the staging area? –  Dror Jan 2 '13 at 8:46

Run crontab -e to edit your user cronjob, and insert this line:

0 20 * * 0 (cd /path/to/myproject && git add . && git commit -m "Automatic Commit" && git push)

Of course you will have to setup your GIT repo including a working remote repository, but that's not in scope of this question.

share|improve this answer

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.