How to clone repository in Git?

Cloning a repository means creating a copy of a repository. git clone command is used to clone a repository. It takes two arguments:

  1. The first argument is the location of the repository that you want to clone. In general, you specify a GitHub URL. But you can even clone a local repository by providing its path.
  2. The second argument is the name of the directory in which you want to clone into. If you don't specify the folder name, then a directory having the name of the repository is created.

Let's say you want to clone Google Test repository, so run the following command:

$git clone

You will find that a directory named googletest is created. If you change into this directory and run ls -a, you will find all the repository files. Also, you will see .git directory that holds a copy of the repository history.

$cd googletest
$ls -a
.             BUILD.bazel    CMakeLists.txt   .gitignore  library.json
..            ci     googlemock  LICENSE         .travis.yml
appveyor.yml  .clang-format  .git             googletest  platformio.ini  WORKSPACE

It is important to note that when you clone a repository, two things happen:

  1. By default, the files present in the master branch is copied which you can check by running git branch.
$git branch
* master
  1. The repository that you have cloned is set as a remote repo for you. You can verify this by running git remote.
$git remote

By default, Git assigns a name "origin" to the remote repo, and because of which you will see a remote repo named origin in the output.