I want to copy my c directory with all subdirectories excluding ./git subdirectory. I do it using rsync :

echo "copy c and sh files "
rsync -a --include='*.c' --include='*.sh' --include='*/' --exclude='*' ~/c/ ~/Dropbox/Public/c
# remove .git directory = do not send it to dropbox. Thx to Tomasz Sowa
rm -rf ~/Dropbox/Public/c/.git

Can I do it better?

2 Answers 2


Just add an explicit exclude for .git:

rsync -a --exclude='.git/' --include='*.c' --include='*.sh' --include='*/' --exclude='*' ~/c/ ~/Dropbox/Public/c

Another option is to create ~/.cvsignore containing the following line along with any other directories you'd like to exclude:


  • 1
    It is specified how you should give the path for --exclude. If you have problems with it, check out this answer.
    – totymedli
    Jan 23, 2018 at 1:34

You can just use rsync --cvs-exclude. It also ignores .git directories.

But take care, that this also ignores directories called core as occurring in Magento source files.

  • 11
    This works for the top level .git directory but not for .git directories in submodules. It also does not ignore Git files like .gitmodules. Jul 17, 2014 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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