What is the best way to back up an entire git repository on external disk?

So I want to be able to back up a git repository that may have several branches onto an external hard drive and then be at a later time be able to copy it back onto my local machine and work with it as usual? I have tried simply copying the working directory folder containing the .git directory and it worked. However, I was wondering if this was the best way or if it had pitfalls later.

  • How to export/import the Jenkins configuration?
  • How to restore Git after fatal file system error?
  • Using Subversion with DropBox
  • restore all refs from git bundle
  • Backup hosted repository to off-site location
  • Can anyone recommend a good backup “system” for a developer?
  • Using Git + TortoiseMerge, failing to load file into TortoiseMerge because of space in path name
  • Use 'git filter-branch' to correct committer dates in last N commits?
  • **Visual Studio 2015, should I commit Project.sln.ide\* files into git?
  • including files in eclipse after git checkout
  • How to remove files from git staging area?
  • What git workflow to use for 2 non-co-located developers?
  • 6 Solutions collect form web for “What is the best way to back up an entire git repository on external disk?”

    Copying the entire working copy using regular file system copy commands works fine. You can also zip/tar the backup.

    If you are worried about disk space, you can also look at “git bundle”, which could produce smaller files.

    You can also get incremental backups by just starting a new repo on the external disk (git clone) and then pull the changes every time (git pull). There is not much difference between a backup and a working copy in a distributed system like git.

    If you don’t have any changes to back up in your work tree, you can use git clone --mirror to create a bare clone with all refs (branches, tags, absolutely everything) copied verbatim. You can then use git push --mirror to keep it up to date incrementally. This is what it’s designed for.

    Copying the entire repo, including the work tree, works as well, but it’s a bit of a pain to do incrementally, and obviously takes up more space.

    That’s about the only way to do it, short of cloning the repository onto the external disk. But either approach is approximately equivalent, except that copying your clone will preserve any repo-specific config settings.

    Summarizing,

    • You can just copy the damn directory, sure it works.
    • You can clone.
    • You can git bundle or git archive

    You can also,

    which you can dump into a single file that you can import later from.

    $ git fast-export --all | (cd /empty/repository && git fast-import)
    

    There is no pitfall here, git is a fully distributed SCM. Copying a working copy with the .git directory is sufficient backup.

    Copying the whole thing or using a sync tool is fine. The repo is fully contained and portable.

    Git Baby is a git and github fan, let's start git clone.