views:

747

answers:

4

If I have a clone of a git repository as a cached copy on a remote server for capistrano/vlad style deployment, is it better to do

A) git archive --format=tar origin/master | (cd #{destination} && tar xf -)

or

B) cp -R cached-copy #{destination} && rm -Rf #{destination}/.git

?

To Clarify, the repository is already on the remote server, and I just want to copy a particular version to a releases directory on the same server during deployment.

+3  A: 

A)

You save the network overhead of transferring the .git directory which could possibly be quite large depending on how much history and objects not in the current HEAD.

If you ever wanted to have an actual git repository on the remote end you're better off pushing to a real repository and only having to change the deltas.

Otto
+2  A: 

Also someone may have already written your code for you.

vigetlab's capistrano_rsync_with_remote_cache

I use this with Subversion and it works well for me.

Otto
Aha; exactly the answer I was going to write myself: rsync.
strager
+7  A: 

I'd say actually

rsync -avP /local/repo/* server:/remote/repo

This works as long as it's OK to skip all the dot files in the repo, not only .git. If you want to skip only .git then you'll need the -f option and the man page.

I love rsync. Works great and most times you can use it just as you would use scp!

Norman Ramsey
I started going with the git archive version at first, but realized that it was missing the git submodules. Therefore, using the using rsync is a great option that I didn't think of. Thanks Otto (great name by the way) and Norman!
ottobar
+2  A: 

Neither!

A better way of doing this is to:

  • git fetch your cache
  • Clone the cache to your current dir (with the --no-checkout options enabled)
  • Checkout the commit you want.

When you do a local clone Git uses hardlinks. That means, until you modify a file, which you wont, you can have 1,000 deployments and use (virtually) only the space you would need for one. This way is also alot faster archiving or rsync.

Chris Lloyd