tags:

views:

707

answers:

5

This question probably is based on my lack of understanding of the role of .gits and git repositories in general but:

Can I rsync a dir with content that I created with git init between machines ?

I have a repository on my laptop, and the only way to get it away from there is scp/rsync to a remote host, from which I can download it again. Could I rsync the complete directory structure between these hosts?

+4  A: 

Yes, that is possible. IIRC, git uses a relative approach. So it's safe to sync it with another computer.

Ikke
It is possible (with the caveat that filesystem-based remotes and alternates might not work) if you don't do any work on the repository during rsync.
Jakub Narębski
+1  A: 

Yes, rsyncing the .git dir is possible and will result in a complete clone of the repository.

Bombe
+1  A: 

Yes you can, but you should do so with a bare repository, as illustrated in this thread.

$ git clone --bare ./projet projet.git
$ rsync -a --stats --delete ./projet.git/ votre.serveur:~/projets/projet.git/
VonC
Bare repository is only needed when you want to push to that repo. Bit if you just copy the repo each time, you can just do it with a full repo.
Ikke
You can use rsync for full repository as well. There is nothing special about bare repository if you use rsync.
Milan Babuškov
@Ikke: true, I usually do that kind of operation with the intent of pushing to it.
VonC
+4  A: 

You can rsync without any problems, but if you have some remotes declared with hostnames which are local to the machine (i.e. stored in /etc/hosts only) then those obviously won't work.

However, is there some reason why you don't use git itself to sync the content?

Milan Babuškov
I was figuring that as my remote server doesnt have git I couldnt git push to it
svrist
True, if you want to use push via SSH, then you have to have git on server too (but you can have it installed locally, and use `--receive-pack` option to `git-push`, and similar option for fetch/pull/clone). If you want to push via HTTP, you need to have only web server with WebDAV, configured to allow push access for you (no git on server required).
Jakub Narębski
+2  A: 

There are a few possibilities:

  • You can just rsync the .git repository (or even whole repository together with working directory), provided that you don't have any activity in repository during rsyncing (same disclaimer as for using rsync:// protocol).

  • You can clone or fetch using deprecated rsync protocol (where repository URL / location looks like this: "rsync://host.xz/path/to/repo.git/"). Note that this protocol is deprecated, because if there is any activity in repository, you can get corrupted clone (or fetch).

  • Or you can create git bundle, rsync it or scp it on other machine, and then clone or fetch from bundle.

Jakub Narębski