Home

Git Clone - Complete guide to cloning repositories with Git CLI

Cloning a remote repository

To clone a repository into your PC, you need to have the URL of the repository that needs to be cloned. Then using the URL, run the following command.

git clone <repo_url>

The above command will clone the repo into a new folder in your current path. For e.g., if you run git clone https://github.com/awsm-page/awesome-repo.git on your desktop, a new folder with name awesome-repo will get created on your desktop.

You will get an error if you already have a non-empty folder with the same name in your path.

Cloning into any specific directory(i.e., folder)

If you don't want to clone the repo into a folder with a specific name, then you can specify it in the git clone command.

git clone <repo_url> <directory_name>

The above command will clone the repo into a new folder in your current path, but with the name that you've provided in the command. For e.g., if you run git clone https://github.com/awsm-page/awesome-repo.git amazing-repo on your desktop, a new folder with name amazing-repo will get created on your desktop.

You can specify the path instead of the directory_name i.e., you can use git clone <repo_url> . to clone the repository into the current directory

Cloning a repository that has submodules

To clone a git repository along with submodules, use the following command:

git clone --recurse-submodules <repo-url> <directory_path>

If your git version is under 2.13, you need to use --recursive option instead of --recurse-submodules. You can use git --version to find version of Git CLI installed on your PC .

Clone sub modules after cloning the repository

If you want to clone the sub modules separately after cloning the repository(without sub modules), then you can use the following command inside the git repo:

git submodule update --init --recursive

You need to cdinto the git repo to run the above command.



Last Updated on

Next Post: Rules vs Guidelines →

Comments