How To Clone a Repository From GitHub Using Your Terminal

Just set up a new repository on GitHub? Checking out someone else’s work? Want to contribute to another project? The first step is getting that repository downloaded to your machine. There are a few ways to do this. Using your terminal is, in my opinion, one of the easiest and quickest ways. Let’s walkthrough how to do this.

I highly recommend taking a look at our terminal guide. You can find it here:
Introduction to the Terminal

If you feel like you’re ready, let’s get started!

How to create a new repository on GitHub

For this guide, we’ll download our own, newly created repo. So let’s create one. Make sure you’re logged into your GitHub account and go to github.com/new

You’ll be prompted to set up a new repository. Your page should look pretty similar to this:

Toward the top you should see Owner & Repository Name *
Make sure you’re in your account under Owner. Under the Repository name give your new repo a name. For this example, I’ll call mine how-to-clone.

Next, scroll down to the section titled Initialize this repository with: and make sure you select Add a README file. This is important.

Once you’ve selected to setup your repo with a README file, you can click the button at the bottom of the page that says Create repository.

You should now be redirected to a page similar to this:

Click on the big green button in the top right that says Code.
A dropdown menu should show up with a few options.

Go ahead and click on the copy button that I have marked above in the red circle. Now it’s time to clone the repository.

How to Clone a Repository from GitHub

Open up your terminal. Make sure to navigate to the directory you’d like to place your repo. If you’re unsure how to do this, checkout the resource I linked in the beginning of this guide: Introduction to the Terminal.
I’ll choose to place this repo on my desktop. So in my terminal I’ll change directories to my desktop.

cd desktop

Once you’re in the location you’d like to clone your repository to, just type in

git clone <link to repo>

Replace <link to repo> with the link you copied earlier. Hit enter and your repo should begin downloading to your machine in the specified location. By default, it will create a folder named with the repo’s name you created. If you’d like to change this name, just write the following:

git clone <link to repo> <new name>

For example:
git clone https://github.com/dustinusey/how-to-clone.git myAwesomeProject

I cloned the repo down from GitHub and then changed the name to myAwesomeProject.

Please note that this only changes the name of the repo on your local machine, not on GitHub.

That’s it! That’s all there is to cloning a repo from GitHub using your terminal. It’s not a complicated process at all. Using the terminal can be intimidating but it isn’t as scary as you may think.