Git – How to Backup a GitHub Repository

backupgit

What is the best way to create a local backup of a git repository hosted on GitHub, given the following requirements?:

  1. The local backup should be a bare repo.

  2. The backup should include all branches.

  3. It should be easy to (incrementally) update the backup.

Basically, I want a perfect mirror, with the possibility to update easily. As such, the command

git clone --mirror git://github.com/...

comes to mind, but as far as I can tell, that doesn't allow for an easy update (I'd have to delete and recreate my local backup). Also, the mirror option for git clone seems quite recent, I don't have it on some of the systems I'm working on (which have slightly older versions of git running).

What is your recommended solution for this kind of problem?

Best Answer

To create the mirror:

git clone --mirror git://github.com/user/project.git

To update:

cd project.git
git remote update

To update without changing the current directory:

git --git-dir project.git remote update