Written by:
You can clone a git repository as simply as follows:
1$ git clone <git-repository-url>
<git-repository-url>
should be replaced by the link of the repository that you want to clone, like this:
1$ git clone https://github.com/4GeeksAcademy/html-hello
Cloning a repository creates a local copy of the desired project/repository on your computer, which syncs between the two locations (Remote-Local).
In other words, cloning a repository means downloading a complete copy of it to your computer. And what does a complete copy mean? Well, it means that after cloning a repository, you will have the entire history of the repository on your computer.
So why clone a repository you may ask? Cloning a project has many benefits as:
And all this without the need to be connected to the internet. We will only need an internet connection when we want to "share" our work with someone else, or we want to upload our work to GitHub.
In the following section, we will dive in on more detailed examples of how to clone a github repository and also how to fork any github repository.
For this example, we will clone one of 4Geeks popular repositories, that is 4Geeks react-flask-hello. The steps to clone this repository are as follows:
my-first-cloned-repo
as shown below.cd
and add/copy the directory/folder location/path. Since we want to save the repository in our folder my-first-cloned-repo
, let's copy the folder's path C:\Users\rafam\Programming Projects\my-first-cloned-repo
and paste it on the terminal, you can also drag and drop the folder on the terminal and press enter1rafam@LAPTOP-LLV85FV6 MINGW64 ~ 2$ cd 'C:\Users\rafam\Programming Projects\my-first-cloned-repo' 3 4rafam@LAPTOP-LLV85FV6 MINGW64 ~/Programming Projects/my-first-cloned-repo
git clone
along with the copied URL1rafam@LAPTOP-LLV85FV6 MINGW64 ~ 2$ cd 'C:\Users\rafam\Programming Projects\my-first-cloned-repo' 3 4rafam@LAPTOP-LLV85FV6 MINGW64 ~/Programming Projects/my-first-cloned-repo 5$ git clone https://github.com/4GeeksAcademy/react-flask-hello.git
1rafam@LAPTOP-LLV85FV6 MINGW64 ~ 2$ cd 'C:\Users\rafam\Programming Projects\my-first-cloned-repo' 3 4rafam@LAPTOP-LLV85FV6 MINGW64 ~/Programming Projects/my-first-cloned-repo 5$ git clone https://github.com/4GeeksAcademy/react-flask-hello.git 6 7Cloning into 'react-flask-hello'... 8remote: Enumerating objects: 1024, done. 9remote: Counting objects: 100% (33/33), done. 10remote: Compressing objects: 100% (22/22), done. 11Receiving objects: 99% (1014/1024), 6.82 MiB | 6.79 MiB/seused 991 12Receiving objects: 100% (1024/1024), 8.86 MiB | 7.31 MiB/s, done. 13Resolving deltas: 100% (521/521), done.
It is important to understand that you can clone any repository not only from GitHub but from any other site if you have the git URL. Remember that you clone a repository with the git clone <url>
command.
The difference between forking and cloning a project/repository really comes down to how much control a developer is allowed to have over a given repository.
By Forking, you can make your own copy of a repository somewhere else (for example, GitHub). Owning a copy of the repository means that you can make changes to it without affecting the original repository.
Cloning creates a local copy of a repository. Imagine doing that by downloading a repository to your computer's local storage. Clones have references to their original repositories, unlike forks.
So you want to make your own copy of a repository, let's make a copy of the one that we cloned in the example above, 4Geeks react-flask-hello.
The steps to fork the repository are the following:
Go to the GitHub repository 4Geeks react-flask-hello
Click the Fork button located in the top right corner of the page
main
branch only) that allows you to only copy the main branch, if you want to copy the whole repository with all of its branches, then this box should be unmarked.You can also use the GitHub Desktop App to clone a repository to your computer, once you have downloaded the GitHub Desktop App here, and being signed to the GitHub website and Desktop App, then you can follow these steps:
The GitHub Desktop App will automatically open on your computer and a window called Clone a repository will be displayed. Here you can confirm the repository to be cloned, and you can change the local path where the repository will be saved by clicking the Choose... button, or you can just copy the path and paste it into the corresponding field.
The following video describes the step by step of everything that has been explained in this GitHub Clone Repository article: