Sometimes, you might want to use a repository on your machine saved remotely on GitHub; to do this, you will need to clone the repository to your machine. Learning to clone a Git repository is vital because you cannot contribute to or work on a repository that you haven’t cloned to your computer.
What’s The Use Of Cloning In Git?
Git’s primary feature allows developers to create savepoints for their files; you can revert to these savepoints in the future. While you can use version control locally on your machine, using Git remotely on GitHub has added benefits.
Some of the advantages of using Git remotely are:
- The ability to access your files on any computer connected to the internet.
- Sharing files with other users around the world.
- Giving teams the ability to work simultaneously on a particular project.
- Open-source projects can be accessed and updated by developers around the world.
- You can track file changes more efficiently using a Graphical User Interface.
You would observe that most of the critical reasons for remote repositories have to do with the interconnectivity of developers; that’s because even the best developers have to work in teams. Also, this interconnectivity makes it possible for us to have all the beautiful open-source software that we do today.
When you create a remote repository and commit or push changes to that repository, you’re saving it on GitHub’s server. Any developer who personally wants to work on these files needs to create a copy of the uploaded files on their system. Cloning is the process of copying all the commits of that remote git repository so you can use it locally.
Clone A Git Repository Using The Bash Shell
Every operating system has a shell through which human users and other programs can access its services. The Bash shell is the default shell used on Unix-based systems like MacOS and Linux; when you open the default CLI on both operating systems, they’ll be running on the Bash shell. However, Windows users will need to install the Bash shell separately– you can learn how to do that in this article.
If you already have Bash installed on your system, then you can continue with the steps below:
- Open GitHub on your web browser and search for the repository you want to clone.
- On the Code tab of the repository, click on the green-colored Code dropdown button.

- There will be a dropdown of various options, from which you should copy the HTTPS link; this link is within an input box.
- On your CLI, navigate to the location on your computer where you want to clone the repository; to navigate, you would use the
cd
command; for instance:
cd C:/Users/Clouddevelop/Desktop/
The folder you want to clone the remote repository is known as the working directory.
- Next, you should create your working directory using the
mkdir
command, like this:
mkdir education-app
- In your working directory, you use the
git clone
command with the remote repository URL in front, like this:
git clone https://github.com/nabsteve/education-app.git
The repository will get downloaded to your computer and take varying amounts of time, depending on the file size.
Clone A Git Repository Using GitHub CLI
GitHub has its custom command line application which helps to reduce the hassle of having to install Bash on a PC. The steps to clone a repository using the GitHub CLI are as follows:
- Download the GitHub CLI from this page. The program is available for Windows, Mac, and Linux users and is a light installation package.
- Open the installation file and use the default instructions to install the program.
This GitHub application is a CLI application, meaning it can’t run on its own; instead, you should use it within any command line on your computer. - First, you need to authenticate your GitHub account on the command line by typing the following command:
gh auth login
- Select the type of GitHub account you want to log into between Enterprise and GitHub.com.
- Next, you will choose the protocol for Git operations; except you have set up an SSH key, you should go for the HTTPS option.
- Choose if you want to authenticate Git with your GitHub credentials; I chose No in this option.
- Next, you will choose an alternate means to authenticate the GitHub CLI; I chose to use the web browser for this.
- On the browser, you need to log in to your GitHub account and enter the one-time code that GitHub generated for you in the CLI.
- Once you’re signed in, you need to authorize the attempt of GitHub CLI to access your account.
- You would be prompted to type in your password, after which you should see a success message on your browser.
- Next, you will see a message on the CLI that informs you that you’ve successfully logged in.

- Once you log in, you can clone the repository using the
gh repo clone
command with the address to the repository in front. For example:
gh repo clone nabsteve/education-app
You can get the repository address by searching for the repository on GitHub, clicking on the green Code button, and selecting the GitHub CLI tab. Copy the address that you see in the little input box.
- You would have successfully cloned the repository into whatever directory you were in when you ran the command.
Downloading A Repository As Zip
You can also download and work with a git repository on your machine without using a CLI by following these steps:
- Open GitHub on your web browser and search for the repository you want to clone.
- On the Code tab of the repository, click on the green-colored Code dropdown button.
- Select the Download With Zip option from the dropdown.
- Unzip the file in whatever location you want to use as your working directory on your computer, and you should be good to begin work on the downloaded files.
If your computer does not have a default app for unzipping files, you can download and use WinRAR for free.
Downloading a file as zip is an easier path to take for those unfamiliar with using a CLI. However, downloading the file as zip has a significant shortcoming of being an ordinary file or folder and not a git working repository.
When you clone a repository using the command line, you have access to all of that repository’s past, and whatever changes you make will be added to that repositories log. You can view the file’s commit history and the commit messages using the git log
command. The log can be viewed by going into the working directory and typing git log
.