Cloning an existent repository
With Git, it is possible to clone an existent repository to work on it.
There are several possibilities to clone a repository, but the http
, git
, and ssh
protocols are used the most.
If the repository is public
, it will create a folder and everything inside the folder. However, if the repository is private
or protected
, you have to enter an access information or provide a private ssh
key. For example, if you want to clone a Symfony2
repository, type this line to clone it using myProjectName
as the folder name:
Erik@local:~/myProject$ git clone https://github.com/symfony/symfony.gitmyProjectName Initialized empty Git repository in /var/www/myProjectName/.git/ remote: Counting objects: 7820, done. remote: Compressing objects: 100% (2490/2490), done. remote: Total 7820 (delta 4610), reused 7711 (delta 4528) Receiving objects: 100% (7820/7820), 1.40 MiB | 479 KiB/s, done. Resolving deltas: 100% (4610/4610), done. Checking out files: 100% (565/565), done.
Tip
Note that the name after the clone
command is optional. If there is no parameter after the repository location, the repository name will be used.
You probably read the line about compressing objects. In fact, before sending any content, Git compresses objects to speed the transmission.
We will see more uses of the clone
command in the next chapter.