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

Partial clone in Git

If you want to clone only a part of history in Git, use --depth option to create a shallow clone with only specified number of commits :

# Create a shallow clone.
$ git clone --depth <depth> <repository-url>

# Examples:
# Clone only 1 commit
$ git clone --depth 1 https://github.com/libgit2/libgit2

You can also create a shallow clone by specifying a date :

# Create a shallow clone with history after 2018-05-01
$ git clone --shallow-since=2018-05-01 https://github.com/libgit2/libgit2

And more, -shallow-exclude=<revision> allows you to create a shallow clone with history after a commit.