How do I zip up a folder but exclude the .git subfolder
The correct expression is -x '*.git*'
, so the full command should be:
zip -r bitvolution.zip ./bitvolution -x '*.git*'
An explanation from http://selfsolved.com/problems/zip-command-exclude-svn-director:
The correct incantation is
zip -9 -r --exclude=*.svn* foo.zip [directory-to-compress]
You can also add a
--exclude=*.DS_Store*
to exclude the annoying Mac OS X directory display metadata files.Notice that the expression passed to
--exclude
is using the entire original relative directory path as the original string to match against. So.svn/*
by itself doesn't work; the wildcard character in front ensures that it matches.svn
directories anywhere in the directory tree.
If you're trying to zip up a project which is stored in Git, use the git archive
command. From within the source directory:
git archive -o bitvolution.zip HEAD
You can use any commit or tag ID instead of HEAD
to archive the project at a certain point.
If you want to add a prefix (e.g., a top level folder) to every file:
git archive -o bitvolution.zip --prefix=bitvolution/ HEAD
You can also adjust the compression level between 0 (no compression) and 9 (maximum compression) inclusive, for example
git archive -o bitvolution.zip -9 HEAD
For other options, see the help page (git help archive
).
I added backslash:
zip -r bitvolution.zip bitvolution -x \*.git\*
man page about backslash:
The backslash avoids the shell filename substitution, so that the name matching is performed by zip at all directory levels.