Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

push vs. bundle vs. tar zcvf -- to backup entire local .git

Tags:

git

I can backup my local .git by pushing it to a repository in two steps:

git push --all ~/gitrepo
git push --tags ~/gitrepo

I can back it up using git bundle.

I can back it up by simply copying the entire directory or archiving it (compressed!):

tar -zcvf gitrepo.tgz .git

And there are probably additional ways to backup an entire local .git.

The question now is whether they are really equivalent? (for example, the logs subdirectory isn't pushed)

What are the advantages of the git push method vs. git bundle?

Can tar -zcvf be considered "the perfect git backup"?

like image 823
WinWin Avatar asked Jul 15 '11 02:07

WinWin


People also ask

How do I backup a .git folder?

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.

Does git clone copy entire repository?

git clone is primarily used to point to an existing repo and make a clone or copy of that repo at in a new directory, at another location. The original repository can be located on the local filesystem or on remote machine accessible supported protocols. The git clone command copies an existing Git repository.

Can you push to a git bundle?

You cannot push directly to a bundle file. A bundle file is a compressed representation of a repository, and to modify it would involve unbundling, pushing, and bundling again. One way to do this is as you said, create a new bundle every time you want to make a backup.


1 Answers

I use Git bundle

git bundle create /tmp/backup.git --all --tags --remotes

You can receive it as if it were a repo:

cd myworktree
git pull /tmp/backup.git

But also see

  • How to update a git clone --mirror?
  • "fetch --all" in a git bare repository doesn't synchronize local branches to the remote ones
  • Git doesn't clone all branches on subsequent clones?

Completeness, notes

For complete backup (thing of git-rerere cache, stashes, hooks, configuration files) I suggest using rsync

rsync -hxPavilyzH --stats --delete .git/ backup@remote:/repo/mirror.git/

Alternatively:

  • Is it possible to push a git stash to a remote repository?
  • copy the rerere cache directory
like image 148
sehe Avatar answered Oct 01 '22 02:10

sehe