How to backup a local Git repository?

前端 未结 8 1184
伪装坚强ぢ
伪装坚强ぢ 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:21

    The way I do this is to create a remote (bare) repository (on a separate drive, USB Key, backup server or even github) and then use push --mirror to make that remote repo look exactly like my local one (except the remote is a bare repository).

    This will push all refs (branches and tags) including non-fast-forward updates. I use this for creating backups of my local repository.

    The man page describes it like this:

    Instead of naming each ref to push, specifies that all refs under $GIT_DIR/refs/ (which includes but is not limited to refs/heads/, refs/remotes/, and refs/tags/) be mirrored to the remote repository. Newly created local refs will be pushed to the remote end, locally updated refs will be force updated on the remote end, and deleted refs will be removed from the remote end. This is the default if the configuration option remote..mirror is set.

    I made an alias to do the push:

    git config --add alias.bak "push --mirror github"
    

    Then, I just run git bak whenever I want to do a backup.

提交回复
热议问题