Boring Background - Summary: I know we're not using GIT properly!.
This started as a small hobby project and has spiralled - my company uses Git to track/manage changes to a bespoke web-based software platform and act as a central repository. Approximately 300 mobile devices are then set to pull to a local cloned repository on start up from a self-hosted intranet server so that they may access the latest version of the software when not connected to the network (we make use of branches so that they are only exposed to mature/tested code).

We've now moved on a step - we have a database of "parts" that is updated daily. I have created a separate version of this database using cron scripts to create a standalone version that could be opened on a local "unconnected machine".

My Problem
I have a set of PHP scripts that take database table data and export it into the flat file format required by the application, and copy any additional images since last cycle into the correct locations. All files are stored in /var/www/clonedrepository

I then want to run the following commands on the directory:

git add .
git commit -m "Automatic update: todaysdate"
git push

The repository is cloned from /home/git/repository which is served using the git deamon and apache symlink allowing http access (for dumb device cloning) and SSH (for grownups to edit/update).

The problem is, I'm a web programmer and I'm out of my depth. I set up the git repositories and am comfortable with the command line, but I don't know the best place to start.

Side note: There will never be conflicts as no user will edit the data files and the system will not edit anything other than the data files.

So in summary, I've got a central repository on my Ubuntu Linux box (/home/git/repository) that I would like to update daily from a cloned repository (/var/www/clonedrepository) on the same box.


OK, so I worked this out myself...

1) I have set up a script that contains the following lines:

cd /var/www/partsdb/ >> /home/git/push.log
git pull >> /home/git/push.log
git add . >>/home/git/push.log
git commit -a -m "Scheduled Commit: `date`" >>/home/git/push.log
git push >> /home/git/push.log
echo "Push Backup Successful `date`" >> /home/git/push.log

This script moves to the working repository, pulls any changes from the central repository (remember these changes will only affect program files, not data files), adds any altered data files (stored in a /data sub-directory for clarity) commits the changes (including an automatic date based message to track changes/blame) and then pushes back to the repository.

EDIT: I have since added the -a flag to the commit command, which will then remove any files deleted by the automated update scripts (add . added any new files).[/EDIT]

2) I call this script from crontab, executing the script as root (as root is only user who has permission to write in both git's home folder and the /var/www folder) using the command:

0 * * * * root /home/git/gitpush.sh

This runs the script on an hourly basis - while isolated mobile devices will only pull from the database on startup (daily/am) local network users will always have the most up to date version (that has been pushed to master branch).

  • I suspect there may be a cleaner/neater way of running the script, perhaps not as root or by not using crontab, but this is how I've answered my own question. Suggestions still welcome. – kieran_delaney May 17 '11 at 12:23

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.