Take the 2-minute tour ×

What is the advantage of using

git archive master/foo | tar -x -C ~/destination

to deploy a copy of /foo vs. just copying from the the working copy with

cp foo ~/destination/foo

So, unless for some reason you don't want to copy everything over from that sub directory foo in master (or whatever branch you happening to be working on), using cp for deploying to a [destination] would suffice.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

git archive only exports items that are part of the git repository. cp copies everything that's under the specified directory, including the .git directory, files which are ignored by git, etc.

share|improve this answer
I partly agree with the first part. But there's only one .git folder and it's outside of foo so copying foo will not mean that .git folder get's copied... only foo and it's sub-folders. –  dkinzer Oct 29 '10 at 12:35
Also if I've added everything in foo to the previous commit (why wouldn't I) that means foo is exactly like the copy on master branch. –  dkinzer Oct 29 '10 at 12:36
You might not want everything in foo to be copied: think intermediate build products, editor backup files and anything else that is commonly in your .gitignore file. –  Cameron Skinner Oct 29 '10 at 12:46
@Cameron Skinner, I guess that's really the determining factor here. If I don't want to copy everything from foo. Then using git-archive makes a lot more sense. But otherwise cp is just as good. –  dkinzer Oct 29 '10 at 12:51
@DKinzer: The vast majority of projects have at least something in their .gitignore, be it build products, logs, temporary files, local data, whatever. I'd say it's much more common to want to avoid those files, but you're right, if you don't care if they come along, just copy. –  Jefromi Oct 29 '10 at 13:56
show 1 more comment

Your Answer


