Wednesday, May 15, 2013

Backup and Restore Git Repositories

Sometimes you need to move repositories from your local git server to github.com, bitbucket.org or vice versa. the situation where you want to archive the whole "bare" repo, not just a clone with the master or a single branch.

Backup can be done simply by adding --bare to the clone command

git clone --bare git@github.com:modsaid/test-repo.git

This will result in a cloned repo on the filesystem that is similar in structure to a bare repository

Restoring can be done by creating an empty repository on your git server (github.com or bitbucket.org). and running

cd test-repo.git
git push --mirror git@bitbucket.org:modsaid/test-repo.git

voila