There're two ways you can backup your git repository on multiple platforms. First, you can use git remote add command, and second, you can push git bare repository into another git services.
You first have to get the original Git repository on your machine. Then, go into the repository. Finally, use the --mirror flag to copy everything in your local Git repository into the new repo.
git bundle
I like that method, as it results in only one file, easier to copy around.
See ProGit: little bundle of joy.
See also "How can I email someone a git repository?", where the command
git bundle create /tmp/foo-all --all
is detailed:
git bundle
will only package references that are shown by git show-ref: this includes heads, tags, and remote heads.
It is very important that the basis used be held by the destination.
It is okay to err on the side of caution, causing the bundle file to contain objects already in the destination, as these are ignored when unpacking at the destination.
For using that bundle, you can clone it, specifying a non-existent folder (outside of any git repo):
git clone /tmp/foo-all newFolder
Whats about just make a clone of it?
git clone --mirror other/repo.git
Every repository is a backup of its remote.
Expanding on the great answers by KingCrunch and VonC
I combined them both:
git clone --mirror [email protected]/reponame reponame.git
cd reponame.git
git bundle create reponame.bundle --all
After that you have a file called reponame.bundle
that can be easily copied around. You can then create a new normal git repository from that using git clone reponame.bundle reponame
.
Note that git bundle
only copies commits that lead to some reference (branch or tag) in the repository. So tangling commits are not stored to the bundle.
Expanding on some other answers, this is what I do:
Setup the repo: git clone --mirror user@server:/url-to-repo.git
Then when you want to refresh the backup: git remote update
from the clone location.
This backs up all branches and tags, including new ones that get added later, although it's worth noting that branches that get deleted do not get deleted from the clone (which for a backup may be a good thing).
This is atomic so doesn't have the problems that a simple copy would.
See http://www.garron.me/en/bits/backup-git-bare-repo.html
This thread was very helpful to get some insights how backups of git repos could be done. I think it still lacks some hints, information or conclusion to find the "correct way" (tm) for oneself. Therefore sharing my thoughts here to help others and put them up for discussions to enhance them. Thanks.
So starting with picking-up the original question:
Then enriching it with the typical wishes and specifiying some presettings:
The point of view differs on what a "100%" backup is. Here are two typical ones.
git is a developer tool and supports this point of view via git clone --mirror
and git bundle --all
.
git gc
)git is a developer tool and leaves this to the admin. Backup of the git configuration and OS configuration should be seen as separated from the backup of the content.
Most of them are generic for backups.
git gc --auto
git bundle --all
git bundle verify
.git clone --mirror
git fsck
.A cold-copy backup can always do a full file backup: deny all accesses to the git repos, do backup and allow accesses again.
File backups cannot be done with active repos due to risk of corrupted data by on-going commits. A hot-copy provides a fixed state of an active repository for backup purposes. On-going commits do not affect that copy. As listed above git's clone and bundle functionalities support this, but for a "100% admin" backup several things have to be done via additional commands.
git bundle --all
to create full/incremental dump files of content and copy/backup configuration files separately.git clone --mirror
, handle and copy configuration separately, then do full file backup of mirror.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With