Cloning from a local Git repository

If the remote repository you are cloning is located in another directory on the same host, you can clone such a repository like below:

# Use relative path to specify the repository
$ git clone ../php-project/my-project my-project2

# On Windows: Use full path to specify the repository
$ git clone E:/projects/my-project my-project2

# On Linux: Use full path to specify the repository
$ git clone /home/jone/my-project my-project2

Or

# On Windows
$ git clone file://E:/projects/my-project my-project2

# On Linux
$ git clone file:///home/jone/my-project my-project2

Both the two formats of cloning above are using local protocols. But they operates slight differently. The first format is processed like copying files, while the later one is processed like transferring data over network which is generally much less efficient. According to what Git says: “The main reason to specify the file:// prefix is if you want a clean copy of the repository with extraneous references or objects left out”.

And if you want to create a shallow clone from local repository in which --depth option is used, you need to specify the file:// prefix.

# On Windows: A shallow clone from local repository
$ git clone --depth 1 file://E:/projects/my-project my-project2