tar: --exclude=".git": Cannot stat: No such file or directory

Solution 1:

All the options need to be together before the arguments, and the -f flag needs to precede the tar file:

tar -zcv --exclude='.git' --exclude='.gitignore' -f $NAME-$VERSION.tar.gz $NAME-$VERSION

Solution 2:

This gives you what you want:

tar czvf $NAME-$VERSION.tar.gz $NAME-$VERSION --wildcards --exclude=.git --exclude=.gitignore

Solution 3:

It seems you like to filter .git meta directories, the easiest way is using --exclude-vcs to exclude version control system directories:

tar -zcvf $NAME-$VERSION.tar.gz $NAME-$VERSION --exclude-vsc

I have used "tar (GNU tar) 1.27.1" on my Linux machine, it seems mac's BSD General Command(non GNU version) does not support this option.