What command will you use if you want to make an identical copy or a clone of someone else’s Github hosted repo? git clone

Learn git clone command

but but… you may ask, Github allows me to download the files as well, why should I use the clone command? Aren’t we all familiar with those clone and download options that shows up on every Github repo?

Should we clone or download git files?

Clone a repo vs Download a zip

There is a fundamental difference between clone vs download. When you clone a repo, you make a copy of the complete history of the git repo including the .git folder (we learned in the earlier lesson).
When you download the repo, you just download the source files of the most recent commit of the default branch without the .git folder. Essentially, when you download you can’t make use of any git commands, you can’t view the commit messages, you are just not using git at all.

How to use git clone command?

Let us understand git clone command by downloading the WordPress repo from Github.

Note: When you use a git clone command, ensure that you are in the correct directory. Clone command will create a new directory and put the required cloned git repo inside it. You can not have nested Git repositories. Often beginners to Git make this mistake while cloning.

On your terminal window type the git clone command with the URL of the repo you wish to clone.

$ git clone https://github.com/WordPress/WordPress.git

git clone in action
As we can see in the animation above, we successfully cloned the WordPress repo on our system. This is how the WordPress repo looks in  our file system.

git-cloned-repo

The git clone command above created the repo in the directory name WordPress. What if you want to change the name of the directory to something else? Just use git clone command with an additional argument (folder name).

Here is the command to create the cloned repo in the WP folder instead of the default WordPress folder.

$ git clone https://github.com/WordPress/WordPress.git WP