Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

If I tar a folder that is a git repository, can I do so without including the .git related files? If not, how would I go about doing that via a command?

share|improve this question
add comment

2 Answers 2

up vote 10 down vote accepted

Have a look first at git help archive. archive is a git command that allows to make archives containing only git tracked files. Probably what you are looking for. One example listed at the end of the man page:

git archive --format=tar --prefix=git-1.4.0/ v1.4.0 | gzip >git-1.4.0.tar.gz
share|improve this answer
1  
this only archives root git repo. If submodules were used - their directories will be empty. –  Stann May 5 '12 at 5:00
add comment

If you want the archive to include the files tracked by git, but not the git repository itself or any generated or otherwise untracked file, then use git archive.

If you specifically want to exclude .git but include everything else, under Linux or FreeBSD or OSX or Cygwin, tar has a simple option to exclude a directory:

tar -c --exclude .git -f - foo | gzip >foo.tgz

With GNU tar (i.e. under Linux or Cygwin), you can shorten this to tar czf foo.tgz --exclude .git foo.

The POSIX way of creating archives is pax.

pax -w -t -s '!.*/\.git$!!' -s '!.*/\.git/.*!!' foo | gzip >foo.tgz
share|improve this answer
    
Does git compiles on any system where tar is not available? :-) –  Stéphane Gimenez Aug 12 '11 at 23:35
1  
@StéphaneGimenez Probably not. But it does compile on systems where tar has no --exclude option, such as OpenBSD (which admittedly duplicates pax's s option, but that's not a common tar command syntax extension). –  Gilles Aug 12 '11 at 23:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.