Search code examples
gitbackup

so many files in .git directory. slow backing up


Every so-often I backup parts of my harddrive. I don't want to discuss my reasons for doing it this way. What I do want to discuss is that the backup is especially slow when copying the .git directories. Even simple project have ~5000 files in this .git directory! And I'm running multiple of these projects. Together they will only be ~60 mb or so. The git directory has more files then my projects do! This is very inefficient for copying. This is very inefficient for copying: I think ~90% of the time is lost with all these .git directories.

Is there a way to set git to efficiently integrate everything in one big file or so? Or maybe 10 to 50. But not 5000.


Solution

  • Like @VonC said, git bundle is a good way to go but requires some work to be put in place.

    An easier thing to do is to call git gc in the repository before copying it.

    That way all the little files in the .git\objects folder will be packed in few big pack files very fast to copy.

    PS: you could also do a git stash (with the good options) to save all the current changes in the .git folder and that way, you only need to save this .git folder (and no more the working directory). It will be even quicker to backup! After the copy, you will be able to repopulate the entire working directory from the git database using the command git reset --hard HEAD (and stash pop, if needed).