Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create a zip file from a folder and I'd like to exclude the .git sub-folder from the resulting zip file.

I have gone to the parent folder of the one I want to zip (called bitvolution) and I'm doing:

zip -r bitvolution -x ".git"

But it doesn't exclude the .git sub-folder.

I've tried various combinations, -x .git*, -x \.git/*, -x .git/\*, -x \.git/\*. I've also tried using the full path for the exclude argument... but just didn't get there.

share|improve this question
up vote 86 down vote accepted

The correct expression is -x *.git*, so the full command should be:

zip -r bitvolution -x *.git*

An explanation from

The correct incantation is

zip -9 -r --exclude=*.svn* [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.

share|improve this answer
Perfect. Thanks. – Tom Feb 28 '11 at 21:42
I had to wrap the glob in quotes or escape the asterisks with backslashes, like zip --exclude '*.git*' -r directory or zip --exclude \*.git\* -r directory – dimadima May 29 '14 at 19:37
If you're worried about losing other files called something.gitwhatever, you can also use --exclude /.git*. – Erin Call Sep 25 '14 at 21:54
in ZSH I had to add a backslash: -x \*.git\* – DmitrySandalov Dec 6 '14 at 20:14
My preferred alternative to backslashes and quotes in zsh: noglob zip -r someFolder -x *someExcludedFolder* – Sebastien Oct 19 '15 at 14:09

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 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 --prefix=bitvolution/ HEAD

You can also adjust the compression level between 0 (no compression) and 9 (maximum compression) inclusive, for example

git archive -o -9 HEAD

For other options, see the help page (git help archive).

share|improve this answer
Not only will this not include the git folder but also anything that is in the gitignore file will be excluded as well. You sir get an upvote. – JoeMoe1984 Oct 21 '14 at 10:04

I added backslash:

zip -r 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.

share|improve this answer
prepending asterisks with slash forks for me on Ubuntu 14.04 to exclude directories – Dimitry K Mar 23 at 17:04

Assuming you have git installed on the machine you are doing this, you can also use git itself to create your archive.

git archive --format=zip HEAD -o
share|improve this answer

Your Answer


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.