Reputation: 9311
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?
Upvotes: 3
Views: 1480
Reputation: 497292
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.
Upvotes: 7