"Cloning" in simple English means producing identical individuals either naturally or artificially. If yous are familiar with the term, at that place is no surprise what is going to exist in this tutorial. Before coming on to What is Cloning in Git or Git Clone , I hope the reader is well-versed with the process of Forking in GitHub .

Sometimes, non-technical people or the people who have non all the same worked on Git consider these two terms (Git Clone & Git Fork) as similar. Actually, they are, merely with some differences. It is amend to rinse your brain with forking before learning the concept of cloning in Git.

Also, since the basics of Git and GitHub have already been covered in this grade, from now on we volition utilize both of them to perform the operations and procedures on our lawmaking/files. On the greater circle, this tutorial volition make you lot familiar with:

  • What is Cloning?
  • Purpose of Cloning
  • Importance of Cloning in Git
  • Cloning a repository and Git Clone control

What is Git Clone or Cloning in Git?

Cloning is a process of creating an identical copy of a Git Remote Repository to the local machine.

Now, you might wonder, that is what nosotros did while forking the repository!!

Git Clone

When we clone a repository, all the files are downloaded to the local machine but the remote git repository remains unchanged. Making changes and committing them to your local repository (cloned repository) volition not affect the remote repository that y'all cloned in whatsoever fashion. These changes made on the local machine can be synced with the remote repository anytime the user wants.

Why Clone a Repository?

Every bit mentioned in the previous sections, cloning downloads the consummate source lawmaking to the local system, let's go through the real reasons why cloning is required ar the outset place:

  • Contribute to Organizational Projects : A centralized system is required for organizations where multiple people work on the same code base. Cloning helps us achieve this motive. By cloning, people can edit the projection code to either fix some outcome or provide some modifications i.e. an extra or extended feature. This definitely helps in producing improve software in less time with greater collaboration.
  • Make use of Open up Source Repositories : A famous idiom in English, "Do not reinvent the cycle" is suitable for this point to sympathise. Similarly, if someone wants to use some functionality that has already been developed by someone else, then why to code it from scratch and waste material time & resources? For east.chiliad. in that location are unlimited opensource repositories are available, which can directly fit into the projects.

Since cloning is so important part of the Git and GitHub journeying, information technology is amend to run into in detail how cloning works. It is a very uncomplicated and straightforward process to which the next section is dedicated.

How does Cloning in Git works?

A lot of people desire to gear up up a shared repository to allow a squad of developers to publish their code on GitHub / GitLab / BitBucket etc. A repository that is uploaded online for collaboration is called an Upstream Repository or a Central Repository .

A primal repository indicates that all the changes from all the contributors pushed into this repository only. So, this is the nearly updated repository example of itself. Sometimes this is often called the original repository . Now, the prototype given below is pretty clear about the concept of cloning.

Git Clone - Cloning a Repo

With respect to the in a higher place image, the cloning process works in these steps:

  • Clone a Repository : The user starts from the upstream repository on GitHub. Since the user navigated to the repository because he/she is interested in the concept and they similar to contribute. The process starts from cloning when they clone the repository it into their local machine. Now they have the exact copy of the project files on their system to brand the changes.
  • Brand the desired changes : Later on cloning, contributors provide their contribution to the repository. Contribution in the form of editing the source files resulting in either a bug fix or adding functionality or perhaps optimizing the code. But the bottom line is, everything happens on their local arrangement.
  • Pushing the Changes : Once the changes are done and at present the modifications can be pushed to the upstream repository.

Annotation : Owner of the repository can allow/disallow direct changes to Central Repository, gear up various notifications(notification for whatever change pushed to cardinal Repo) and many more, just all these settings will exist covered later in this series of Git Tutorial.

Git Clone

Cloning in Git tin can be washed on the cocky-endemic repository or anyone else's repository. In the following section, we will clone the ToolsQA repository bachelor on my GitHub business relationship. You lot can create a new GitHub repository and endeavour to clone the aforementioned.

How to Clone a Repository or use Git Clone Command?

Cloning a repository from GitHub is a simple procedure. But, before cloning, delight ensure you have a repository on your GitHub account. In this section, I will make use of the ToolsQA repository ( reference ).

  1. To clone a repository, go to the repository page which you desire to clone. This tin can exist washed through the side cavalcade on your dashboard.

repository_Section

  1. Press Clone or download push button.

clone_or_download_button

  1. Re-create the code that appears after pressing the button.

copy_clone_code

Annotation : The Use SSH function located beside Clone with HTTPS will be explained in detail in the SSH tutorial but every bit of now we are cloning the repository with https ("Clone with HTTPS") not ssh .

  1. Once washed, open up Git bash on your organisation.

navigate_to_repo

Note : Remember to change the directory to which you desire to clone the repository. I take marked my directory Git Repo ToolsQA in the above image in which I will be cloning the repository from GitHub.

  1. Bank check the directories (or repositories) already created under this directory. (using ls command)

list_all_the_directories

As seen in the image, I have just ane repository under the directory Git Repo ToolsQA.

  1. Press the following control to clone the repository:

git clone <URL>

URL here represents the aforementioned URL that nosotros copied in the third pace.

Git Clone Command

Notation : URL is the link of the repository over GitHub Cloud. Yous tin type this into the address bar in your browser and cheque if the repository page opens or not.

  1. The post-obit message will appear as you press enter.

git_clone_successful

Information technology would take a few seconds to clone the repository onto your arrangement.

Note : Delight note that cloning depends on the cyberspace connectedness and the time would depend on your connection bandwidth. If Git is not able to clone due to a weak connectedness, it would display a fatal error and the user is requested to effort once again until the above message does not appear.

  1. Ostend the cloning by listing the directories once again using the ls command which lists all the files and folder.

list_all_the_directories_after_clone

Since the Centralised Repository in our case called ToolsQA, the aforementioned has been copied to my local motorcar.

Check in the local bulldoze by navigating to it manually.

Cloned_Repo_In_Local_Machine

As clearly seen, nosotros have successfully cloned the repository from GitHub. Now we can work on the files on our local system like normal lawmaking files. Cloning is very helpful equally you might accept guessed and used very frequently by the people using Git or GitHub for their software development. Once the changes are made, the user pushes the changes to the original repository on the cloud (GitHub) and makes it available to everyone who is watching information technology or contributing to it. At present it's the time to articulate the fuzz between Git Clone and Git Fork.