Clone a repository
We might come across many tutorials on my site and also from other sites that require you to clone a repository such as GitHub. This allows developers and learners to speed up the process of code development/learning and to focus on the objectives.
What is a repository ?
A repository, or repo, is a collection of software packages. These software packages might be developed and contributed by one or more developers. A version control system is also used to keep track of all contributions and changes made to the code.
Github is a popular git repository hosting service, with version control.
Many of the tutorials here use code that is hosted in GitHub.
Clone a repository
To clone a repo from Github, we can either simply download the repo from GitHub or run git commands on command line interface (CLI) such as Terminal (Mac) or Powershell (Windows 10).
Downloading from GitHub
Go to the URL where the repo is hosted. For example, this is where my sample repo is hosted.
https://github.com/Prakashash18/flutterBlogs
Click on the button. Only repositories will have this button present.
Click on Download Zip to download the repo. You can then unzip the file using any unzipping tool.
Clone using Git Commands
To clone using the git CLI, you first need to ensure that you have the git cli installed in your machine. You can refer to the tutorial here if you’ve not done so.
To check if you have git, simply open the terminal (Mac) and run git. If git is installed, you’d get recommended usages as shown.
Once you know git works, you can then clone a repository by running commands. The command is as shown:
Git clone needs the URL of the repo. Run this command at a location where you want the downloaded repo to be stored. In order to find out where you are in the file structure, you can run the pwd command. [print working directory]
This shows that i am in my home directory (/Users/prakash). If i want to store my repo in a new folder, i can first create one. One way is just to use Finder on a MacBook and create a new folder. Another CLI way is to run the command mkdir. [make directory]
This creates a new folder named flutterTest. To go into the folder, run the cd command. [change directory]
Now you can run the git clone command with the URL of the repository.
This will clone the repo onto your local machine. To see this, run the ls command, and you should see the repo.
CONGRATS, you have successfully cloned a repository !
To open the repo on VS Code, go to this tutorial.