How to backup a local Git repository?

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

    came to this question via google.

    Here is what i did in the simplest way.

    git checkout branch_to_clone
    

    then create a new git branch from this branch

    git checkout -b new_cloned_branch
    Switched to branch 'new_cloned_branch'
    

    come back to original branch and continue:

    git checkout branch_to_clone
    

    Assuming you screwed up and need to restore something from backup branch :

    git checkout new_cloned_branch -- <filepath>  #notice the space before and after "--"
    

    Best part if anything is screwed up, you can just delete the source branch and move back to backup branch!!

    0 讨论(0)
  • 2020-11-22 08:43

    Found the simple official way after wading through the walls of text above that would make you think there is none.

    Create a complete bundle with:

    $ git bundle create <filename> --all
    

    Restore it with:

    $ git clone <filename> <folder>
    

    This operation is atomic AFAIK. Check official docs for the gritty details.

    Regarding "zip": git bundles are compressed and surprisingly small compared to the .git folder size.

    0 讨论(0)
提交回复
热议问题