How do I backup a git repo?

I am planning to switch from SVN to git. With svn I just copy my repo folder when I want to back it up. However git doesn't have one so what do I do?

Should I create a clone on a separate drive and update by pulling from my project? Then I can burn/archive this folder and it will have all the history?

This is probably obvious but I want to make sure when it comes to backups. I still pretend there is a root repository.

1

5 Answers

You just copy it. git does use a repo folder, it's just hidden from normal directory views. (The folder is named .git on *nix systems, so it only appears if you use ls -a. I assume that it sets the "hidden" attribute in Windows, but I've never used git in a Windows environment, so I'm not certain about how it's handled there.)

4

The akira answer is correct, but you can add --mirror to create a bare repo (for a slightly smaller backup).

We use the following strategy (almost exactly):

git clone --mirror yourrepo backup.repo
tar cjf backup.repo.tar.bz2 backup.repo
scp backup.tar.bz2 ssh://somewhereelse

Then, to recover from your backup:

tar xjf backup.repo.tar.bz2
git clone backup.repo yourrepo
1

I'm using git bundle. For making a copy file (one backup file) execute:

git bundle create backup.bundle master

To restore the repository with branch master simply clone the backup.bundle file:

git clone backup.bundle -b master my-project

create a new clone somewhere else:

 % git clone yourepo somewhereelse

btw, git has a repo folder, you can locate it in your working copy underneath the subdirectory .git. every working copy has that "repo folder".

1

I don't want to repeat other answers (backing up .git directory is a good start that should work well if you're only person working on repo) so I'll just add that you can try our github backup
Full disclosure: I work for company that is making this backup solution.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like