Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backup a GitHub repository

Tags:

git

backup

What is the best way to create a local backup of a git repository hosted on GitHub, given the following requirements?:

  1. The local backup should be a bare repo.

  2. The backup should include all branches.

  3. It should be easy to (incrementally) update the backup.

Basically, I want a perfect mirror, with the possibility to update easily. As such, the command

git clone --mirror git://github.com/... 

comes to mind, but as far as I can tell, that doesn't allow for an easy update (I'd have to delete and recreate my local backup). Also, the mirror option for git clone seems quite recent, I don't have it on some of the systems I'm working on (which have slightly older versions of git running).

What is your recommended solution for this kind of problem?

like image 537
Michael Goerz Avatar asked Aug 09 '09 16:08

Michael Goerz


People also ask

Does GitHub have a backup?

Github is not a backup service and companies that rely on the hosted product should have a backup solution in place. Github, like most SaaS platforms, follows the Shared Responsibility Model in which responsibilities are divided between the platform and the user.

How do I backup a GitHub repository?

The correct answer is to do a: git clone --mirror [email protected]/your-repo. git This will copy your entire repository, notes, branches, tracking, etc.

How is git backed up?

git have a backup mechanism but it's not obvious, git has a --mirror flag that you can use to backup or push a git bare repository. Both of the commands are basically the same, you can push using --mirror flag or add git remote repository and then push using the usual command.


1 Answers

I am not sure it could cover all your requirements, but you could check out git bundle

git bundle 

This command provides support for git fetch and git pull to operate by packaging objects and references in an archive at the originating machine, then importing those into another repository using git fetch and git pull after moving the archive by some means

What I like about that solution is the single file produced, with exactly what I want in it

git bundle will only package references that are shown by git-show-ref: this includes heads, tags, and remote heads.

machineA$ git bundle create file.bundle master 

Note: Kent Fredric mentions in the comments a subtlety from git rev-list:

--all 

Pretend as if all the refs in $GIT_DIR/refs/ are listed on the command line as <commit>.

He adds:

your current bundle will only bundle parents of the commit, you'd probably need to specify --all to get a complete bundle of everything (branches that are descendant of master).

To see the difference:

$ 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 
like image 62
VonC Avatar answered Oct 15 '22 01:10

VonC