Completely backup git repo?

Is there an easy way to back up the entire git repository, including all branches and tags?

+109
git backup
Apr 07 2018-11-11T00:
source share
12 answers

How about just making it a clone?

git clone --mirror other/repo.git 

Each repository is a backup of its remote.

+52
Apr 07 2018-11-11T00:
source share
 git bundle 

I like this method as it gives only one file which is easier to copy.
Watch ProGit: a little bundle of joy .
See also " How can I send someone an email with a git repository? ", Where is the command

 git bundle create /tmp/foo-all --all 

in detail:

git bundle will only pack links shown by git show-ref : this includes headers, tags, and remote headers.
It is very important that the substrate used is held in place by the destination.
You can make a mistake if the package file contains objects that are already at the destination, as they are ignored when unpacking at the destination.




To use this package, you can clone it by specifying a nonexistent folder (outside of any git repo):

 git clone /tmp/foo-all newFolder 
+166
Apr 7 2018-11-11T00:
source share

Turning around on some other answers, this is what I am doing:

Repo setup: git clone --mirror user@server:/url-to-repo.git

Then when you want to update the backup: git remote update from the cloning location.

This backs up all branches and tags, including new ones that are added later, although it is worth noting that branches that are deleted are not deleted from the clone (which can be good for backup).

It is atomic, so there is no problem with a simple copy.

See http://www.garron.me/en/bits/backup-git-bare-repo.html

+20
May 29 '14 at 2:47
source share

Extending KingCrunch and VonC's Great Answers

I combined them both:

 git clone --mirror git@some.origin/reponame reponame.git cd reponame.git git bundle create reponame.bundle --all 

After that, you have a file called reponame.bundle that you can easily copy. Then you can create a new normal git repository using git clone reponame.bundle reponame .

Note that git bundle only copies commits that result in some link (branch or tag) in the repository. Thus, convoluted commits are not stored in the bundle.

+8
Jan 04 '19 at 13:58
source share

Everything is contained in the .git directory. Just bring it back along with your project, like any file.

+4
Apr 07 2018-11-11T00:
source share

use git package or clone

copying the git directory is not a good solution because it is not atomic. If you have a large repository that is time consuming and someone is pushing your repository, this will affect your backup. This issue will not occur when cloning or creating a package.

+4
Apr 11 '13 at 3:54
source share

You can back up git with git-copy with minimal storage.

 git copy /path/to/project /backup/project.repo.backup 

Then you can restore your project with git clone

 git clone /backup/project.repo.backup project 
+3
Jun 03 '15 at 3:44
source share

The correct IMO answer is git clone --mirror . This will completely backup your repo.

Git clone mirror clones the entire repository, notes, headings, links, etc. And it is usually used to copy the entire repository to a new git server. This will destroy all branches and everything, the entire repository.

 git clone --mirror git@example.com/your-repo.git 
  • Usually repo cloning does not include all branches, only the Master.

  • Copying the repo folder will β€œcopy” only those branches that have been extracted ... therefore, by default, this is only the Master branch or other branches that you extracted earlier.

  • The Git bundle command is also not what you need: "The bundle command will pack everything that is usually wired using the git push command into a binary file that you can send to someone via email or put on a flash drive, but then unzip to another repository. "( What is the difference between git clone --mirror and git clone --bare )

+2
May 14 '18 at 19:18
source share
 cd /path/to/backupdir/ git clone /path/to/repo cd /path/to/repo git remote add backup /path/to/backupdir git push --set-upstream backup master 

this backs up and does the setup, so you can do a git push to update your backup, which you probably want to do. Just make sure that / path / to / backupdir and / path / to / repo are at least different hard drives, otherwise it doesn't make much sense.

0
Apr 22 '15 at 10:14
source share

Here are two options:

  • You can directly take the tar of the git repo directory, as it has the full contents of the repo on the server. There is a small chance that someone might work with the repo when backing up.

  • The following command will give you an empty repo clone (as on the server), then you can take tar from the place where you cloned without any problems.

     git clone --bare {your backup local repo} {new location where you want to clone} 
0
Jul 25 '15 at 17:02
source share

If it's on Github, go to bitbucket and use the "import repository" method to import the github repository as a private repo.

If it’s in a bit bag, do the opposite.

This is a complete backup, but it remains in the cloud, which is my ideal method.

0
Jul 02 '19 at 0:05
source share

As far as I know, you can just make a copy of the directory in which your repo is located, what a!

 cp -r project project-backup 
-7
Apr 7 2018-11-11T00:
source share



All Articles