Cloning a directory in terminal, using ZSH

I'm trying to clone a directory which holds a git repo.

i.e., I have /Users/me/someFolder - someFolder has ALOT of files, like over 250k. It's also a git repo, with a .git directory, and many other hidden files.

Additionally it contains a number of other sub-directories (folders).

So, to clone this, preserving all permissions, copying recursively, and including ALL files/directories in ZSH on Big Sur, do I simply do:

cp -a /Users/me/someFolder /Users/me/otherFolder?

I ask as I've seen other syntax such as:

cp -a /Users/me/someFolder/. /Users/me/otherFolder? (note the .).

Thanks,


The second method also works if otherFolder already exists. Other than that, there is no difference (assuming that /Users/me/someFolder is an existing folder). In more detail:

cp -a /Users/me/someFolder /Users/me/otherFolder

If someFolder is a folder (i.e. a directory — and not a symbolic link to a directory) and otherFolder already exists (and is a directory or a symbolic link to one), this copies /Users/me/someFolder/some/file to /Users/me/otherFolder/someFolder/some/file. If someFolder is a directory but otherFolder doesn't exist, this copies /Users/me/someFolder/some/file to /Users/me/otherFolder/some/file.

If someFolder exists but is not a directory (it's a regular file, a symbolic link, etc.), it is copied to either /Users/me/otherFolder/someFolder if otherFolder is an existing directory or a symbolic link to one, or to /Users/me/someFolder otherwise (regular file, other special file, or non-existent).

cp -a /Users/me/someFolder/. /Users/me/otherFolder

If someFolder is a directory or a symbolic link to one, this always copies /Users/me/someFolder/some/file to /Users/me/otherFolder/some/file, regardless of whether otherFolder existed or not. (Except if otherFolder is an existing file that isn't a symbolic link or a file, in which case the command will fail.)

In all cases, if the thing to copy is a directory, all of its contents are copied recursively, preserving permissions and modification times. (Access times are also preserved, but they're updated in the source.) That comes from the -a option.

An equivalent command is

rsync -a /Users/me/someFolder/ /Users/me/otherFolder

Note the trailing / on the source so that /Users/me/someFolder/some/file is copied to /Users/me/otherFolder/some/file. If the source was /Users/me/someFolder, it would be copied to /Users/me/otherFolder/someFolder.

rsync is equivalent to cp -R in simple cases, but it's cleverer about not copying files that are already present in the destination folder, so it's good for resuming an interrupted copy or for doing incremental backups. Rsync also has a lot of options to do things like select which files to copy.