How to Clone a Repository using HTTP and SSH

We are going to see how to clone a repository using HTTP and SSH in this tutorial on both GitLab and GitHub.

Working with Git could be a challenge for newbies. For that very reason I have made these basic tutorials to help the ones struggling with it.

Before we progress, let us understand the most cardinal question that you must have once wondered about:

What is Cloning?

Cloning is nothing but copying the code on your local drive. So that you can start working locally on it, and then as and when necessary push your code later on to reflect on one common repository.

In layman’s term, it is nothing but downloading someone’s code on your own machine.

Be it be GitLab or GitHub, the process always remains the same. I will show you an example on how do you clone if your code is on GitLab and how do you clone when your code is on GitHub repository.

How to Clone a Repository (Pre-Steps)

These are initial steps first. You need to open your console and navigate to the folder where you wish to clone the repository.

Step 1: On the drive of your choosing, create a folder where you wish to clone the code.

creating a empty folder

I choose it to be my D: drive. I have created a folder named Git repositories. Let us dump everything here. You can copy the code wherever YOU want.

Step 2: Right click in the blank area, and do a git bash.

git bash here option

Something like this might have opened for you.

git bash terminal

It’s your terminal or console.

Ways to Clone your Repo

There are mainly two ways you can clone:

  • Using SSH
  • Using HTTP

Let us look at the simpler one first.

How to Clone Repository Using HTTP

Remember all of this is before me assuming that you already have an account on GitHub and GitLab. You have git installed on your system, etc. etc.

On GitLab

Let us see how to clone using HTTP on GitLab first.

Step 3: Sign in to your GitLab account if you are not already logged in.

git lab login page

Step 4: Then navigate to your project, i.e. where the code is located.

It must look something like this:

Look for the Clone option

Step 5: Look for the Clone option then click on the dropdown.

copy option available

Step 6: Click on the copy symbol next to the repository textbox under “Clone with HTTPS” option.

The repository is now copied in your clipboard.

Step 7: Navigate back to the open terminal or console, and type

git clone

then right click and paste.

paste repository for cloning in terminal

Step 8: Once you have pasted the repository it might look something like this:

command to clone repository

So basically the command is:

git clone <repo>

where repo is your HTTPS repository link that you had copied.

Step 9: Press enter and let the magic begin.

cloning begins

You will notice that in the folder that you had created in Step 1, has a new folder now of your project.

a new folder is created

That is the code that has been cloned.

Go ahead and open the folder in Visual Studio Code or any other IDE that you are using and start coding.

VSC open folder

On GitHub

Github is fairly simple too. Follow the following steps if your project or code that you are trying to clone is in GitHub.

Step A: Login into Github using your credentials, if you haven’t already.

github login page

Step B: Navigate to your project that you want to clone. Look for the green button that says Copy. It could also say in some cases – Clone or Download. Just click on it:

Code option for cloning

Step C: A small box will flare that would say ‘Clone with HTTPS’. Just click on the clipboard symbol to copy the repository.

copy to clipboard option

Then repeat Steps 7 – 9 to clone the repository.

How to Clone Repository Using SSH

The process is really the same, however you must understand what SSH is first.

SSH or Secure Shell is nothing but another protocol just like HTTP in which you are basically remotely logging in to another computer using your own. It is usually preferred to HTTP owing to the strong authentication it provides that basically takes care of security.

So, with the help of SSH-Agent we are basically generating a key that will be used to sign in just once into the client’s system, and then we don’t have to keep signing in again and again in order to access it. let us say your client’s system.

It basically provides a socket over which the user and client’s interaction happens.

SSH-Agent is there by default in a Linux based system. If however, you are using a different operating system, like Windows, you might have to follow these steps to start off:

Step a: Open your Git bash and navigate to the folder where you want all the action to happen. Type the following:

 eval "$(ssh-agent -s)"
ssh agent command

Step b: Press Enter, and a process ID will be generated. It means that the SSH-Agent is up and running on your system.

generate pid

In this case the process ID is 229.

Step c: Now we need to add SSH keys. Type the following command next and press Enter:

ssh-add ~/.ssh/id_rsa
ssh key command

Now the keys are added to your account.

The next steps are very similar to what we did in HTTP.

Using GitLab

Basically repeat the Steps till Step 5, then instead of copying the HTTP bit, this time copy the SSH repository as shown.

copy to clipboard option in how to clone a repository tutorial

Then repeat the steps from Step 7 – 9.

Using GitHub

In a similar fashion in GitHub you have to repeat all the steps till Step B. Then click on Use SSH option as shown in the image below:

how to clone a repository

Then click on the copy to clipboard button shown next to it.

clone a repository using ssh key

And repeat Steps 7 – 9.

That’s it!

Hope this how to clone a repository post turned out to be useful.

Scottshak

Poet. Author. Blogger. Screenwriter. Director. Editor. Software Engineer. Author of "Songs of a Ruin" and proud owner of four websites and two production houses. Also, one of the geekiest Test Automation Engineers based in Ahmedabad.

You may also like...

1 Response

  1. April 11, 2021

    […] have already seen How to Clone a Repository using HTTPS and SSH before, we will see how to generate a new SSH key in this […]

Leave a Reply