What does the Git clone command do?
Experience Level: Junior
Tags: GitSource control
Answer
The git clone
command is used for creating a local repository from another repository.
It can be executed like this:
git clone <URL> <Folder>
- The URL can be either physical path to anoher local repository (folder), or HTTP, HTTPS or SSH URL to the remote reposiory.
- If you don't provide the <Folder> parameter, the repository will be created in a newly created folder that will be automatically derived from the <URL>
- If you want to clone the repository directly to the current folder (use
git clone <URL> .
), the current folder must be empty
When the git clone
is executed, it does the following steps for you:
- New empty folder is created in your current folder
- New empty .git folder is created in a newly created folder (this .git folder will contain all data of the target repository after the next step is completed)
- Data from the target repository .git folder is copied to your newly created .git folder
Related Git job interview questions
How do you check what files are changed in your Git workspace?
GitSource control JuniorWhat is Staging Area (or Index) in Git?
GitSource control JuniorHow do you add a new file to the Git remote repository?
Git JuniorWhat is a git commit command?
GitSource control JuniorHow can you identify who changed the specific file under version control and what were the changes?
GitSource control Junior