I came across git clone /path/to/repository
in my Git tutorial. What does this command do and when will you use it?
Asked
Active
Viewed 2,321 times
-5

Ni9elF
- 51
- 1
- 10
-
1https://git-scm.com/docs/git-clone – Biffen Oct 29 '18 at 13:15
-
2Hello and welcome to StackOverflow. Please take some time to read the help page, especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). And more importantly, please read [the Stack Overflow question checklist](http://meta.stackexchange.com/q/156810/204922). You might also want to learn about [Minimal, Complete, and Verifiable Examples](http://stackoverflow.com/help/mcve). – Clijsters Oct 29 '18 at 13:48
-
1It clone an already local repository in another directory. Except for tutorial/learning purpose, you will never do that but clone a remote repository. But to learn git pull/push workflow, that make a lot of sense! – Philippe Oct 29 '18 at 19:30
-
@Philippe thank you for your explanation. It helped me understand the command and use case much better than the official guide. – Ni9elF Oct 31 '18 at 06:54
2 Answers
1
When there exists a repository at /path/to/repository
, or in Windows-speak, C:\path\to\repository
, then the commands
git clone /path/to/repository # Linux, Unix, Cygwin
git clone C:\path\to\repository # Windows CMD
git clone C:/path/to/repository # Git-for-Windows's shell
create a copy of the repository in the new directory repository
(in the current directory where you issued the git
command). This copy treats the original at /path/to/repository
as the "origin" repository, from which you can pull changes and to which you can push changes.
It is the same as if you had cloned a repository from some remote hosting site; it just so happens that the origin is located on your local disk.
-
Thank you for your answer. The command and use case is much clearer to me now. – Ni9elF Oct 31 '18 at 06:56
-1
It clones a git repository into your desired local path.
Use it whenever you need to work with a git repository in your computer.

yonvela20
- 1
- 3
-
Please add more details to better explain this answer. A new user may not understand "it clones a git repository to your desired local path" much more than "git clone /path/to/repository" – Patronics Nov 03 '18 at 01:38