Tar a folder without .git files?
Simplest answer: Add --exclude-vcs
. This excludes all version control system directories
Personally I use
tar --exclude-vcs -zcvf foo.tar.gz ./FOLDER_NAME
so all you need to do is add the --exclude-vcs
at the end of the command.
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
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