How to backup a local Git repository?

前端 未结 8 1080
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 08:08

I am using git on a relatively small project and I find that zipping the .git directory\'s contents might be a fine way to back up the project. But this is kind of weird bec

8条回答
  •  情话喂你
    2020-11-22 08:36

    The other offical way would be using git bundle

    That will create a file that support git fetch and git pull in order to update your second repo.
    Useful for incremental backup and restore.

    But if you need to backup everything (because you do not have a second repo with some older content already in place), the backup is a bit more elaborate to do, as mentioned in my other answer, after Kent Fredric's comment:

    $ git bundle create /tmp/foo master
    $ git bundle create /tmp/foo-all --all
    $ git bundle list-heads /tmp/foo
    $ git bundle list-heads /tmp/foo-all
    

    (It is an atomic operation, as opposed to making an archive from the .git folder, as commented by fantabolous)


    Warning: I wouldn't recommend Pat Notz's solution, which is cloning the repo.
    Backup many files is always more tricky than backing up or updating... just one.

    If you look at the history of edits of the OP Yar answer, you would see that Yar used at first a clone --mirror, ... with the edit:

    Using this with Dropbox is a total mess.
    You will have sync errors, and you CANNOT ROLL A DIRECTORY BACK IN DROPBOX.
    Use git bundle if you want to back up to your dropbox.

    Yar's current solution uses git bundle.

    I rest my case.

提交回复
热议问题