3

I am looking for a solution to backup multiple shared git repositories, each with multiple branches, and some of the branches get rebased and forced (I know that's against best practices, but it is something that I have to deal with now)

I was thinking a simple git clone --mirror and then periodically git remote update would be enough, but that won't keep anything that gets rebased with a push force.

I experimented with git bundle and I don't think it's a good solution for what I am trying to do here.

Looking for something incremental, light and easy to use for recovery, I am thinking maybe git format-patch can be used to script the recording of every single new commit that happens anywhere. Is this too much for the task?

Samer Buna
  • 8,821
  • 9
  • 38
  • 55

1 Answers1

7

I think the clone --mirror approach is worth looking back at. If you want to recover a past position of a branch which was force-pushed, just have a look at the reflogs. To be absolutely sure about this, you can set gc.pruneExpire to never, and the same for gc.reflogExpireUnreachable, so that reflogs and unreachable objects will never be removed. That ought to cover you. Important note: reflogs are by default disabled in bare repositories. You can enable them by setting core.logAllRefUpdates.

Do note that the reflogs in the pushed-to repository will contain records of any forced pushes that happen. If you want to be even more sure about this, you could even write an update hook that detects incoming forced updates and records them somewhere special, perhaps by creating a ref, something like refs/backups/mybranch-{n}.

And really, there's nothing wrong with some branches being rebased frequently, as long as it's in a well-defined way, so that no one is caught off guard. The pu branch in git.git is a perfect example of this.

Cascabel
  • 479,068
  • 72
  • 370
  • 318
  • so if I clone --mirror a repo, then a developer rebased a branch in there and deleted commit x, then I remote update the mirror repo, I should still have commit x in the reflog? I tried that and it didn't work as described – Samer Buna Jan 14 '11 at 00:29
  • 1
    @Samer: Oops, I forgot, you have to manually enable reflogs in bare repositories. The config parameter is `core.logAllRefUpdates`. – Cascabel Jan 14 '11 at 00:37