Please note: git itself only perfectly copies the necessary changes to the cloned repository.
If you want to regularly update a copy of your repo, do the following: you create a bare repository as a backup repository, and then repeatedly push there all new changes (there is no need to delete the old backup).
Ok, start by creating your repo
$ cd /tmp $ mkdir myrepo && cd myrepo $ touch hi && git add . && git commit -m "bla"
So this is your repository. Now we create a clone:
$ cd /tmp $ mkdir backup && cd backup $ git --bare init Initialized empty Git repository in /tmp/backup/
Now set up your repo for regular backups ...
$ cd /tmp/myrepo $ git remote add backup /tmp/backup $ git config remote.backup.mirror true
Then copy everything to backup:
$ git push backup Counting objects: 3, done. Writing objects: 100% (3/3), 206 bytes, done. Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. To /tmp/backup * °new branch§ master -> master
And see if this worked:
$ cd /tmp/backup $ git log commit d027b125166ff3a5be2d7f7416893a012f218f82 Author: Niko Schwarz <niko.schwarzàgmail.com> Date: Fri Dec 11 12:24:03 2009 +0100 hi
Tada, you're tuned. So all your script should do is give out a git push backup . There is no need to discard the old backup many times.
An alternative could be rsync to do everything for you:
rsync -av rsync://rsync.samba.org/ftp/unpacked/rsync /dest/dir/
Custom add adds . Starting with version 1.5.4, "git remote add" accepts the "--mirror" parameter, which saves you from having to have "git config remote. Origin.mirror true", and from having to go through --mirror to "git push".