views:

450

answers:

3

What is the fastest path to restore a git repository after a file system error on the main server?

Imagine the central server of your OSS project fails and all commits for two days are lost after restore. How do you get those back? Is it enough just to call "git push" on all clients? Or is there something else I must take into account?

+6  A: 

Every repository is also a backup of the “main repository” (which is “main” by convention only) so a git push from the repository that did the most recent git fetch or git pull should be all it takes—up to its state, of course. You only need to take care of the hooks and such but if you say that only the last two days’ worth of commits were lost those were probably not harmed anyway.

Bombe
+1 for the hooks; I'll apply it tomorrow - out of votes for today :( Sorry.
Aaron Digulla
@Bombe: Congrats, you just passed 5000 points :)
Aaron Digulla
Indeed I did. I’m going to delete all your comments! \o/
Bombe
+1  A: 

A git pull and then a git push should be enough.

Alternately a git push -f will forcibly update the server with your local copy, but this can cause problems for others (if there are multiple committers).

Let us know if you run into any further problems or errors.

wuputah
+1  A: 

I think it might be better to create a new repo on the server:

% ssh user@server
% mv /path/to/repo /path/to/repo.old
% mkdir /path/to/repo
% cd /path/to/repo
% git init --bare

Then push from all the different clones that you have. My thinking is that this would avoid any corrupt files that may be in the old repo, and there should be no loss at all, provided you all work on your own clones, and noone is messing around in the server repo.

Paul Beckingham
+1 Which gave me a new idea: To backup, I clone the repo. This way, the backup is always in a clean state when I ship it to the tape.
Aaron Digulla
That's right. Note that also a "git clone --depth 1 /path/to/repo" is a repo without history, and that could be used to deploy.
Paul Beckingham