Cloning a Remote GitHub Repository

Hands-On Lab


Photo of Terrence Cox

Terrence Cox

Senior Vice President of Content





Working with remote Git repositories is a key concept in distributed source control. Github is one of the most popular public repository sites and you will find yourself working with it regularly. At the completion of this activity, the student will understand how to clone a remote repository from GitHub for use locally.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Cloning a Remote GitHub Repository


Hi there. We've got a little project ahead of us. In this lab, we've been called into a situation where we need to clone a remote GitHub repository for a new developer. We've got a CentOS 7 server we'll need to set up for him to work on, and we've got to get him his own local copy of the GitHub repository. But we've also got to clone that local repo to another one, because he's got a different sort of project he'll be working on initially.

Create Local Repository Location

First off, we've got to make a wide open (as in read/write/execute for everybody) directory to contain the cloned repository. Let's log in to the CentOS server (using the credentials and IP address provided on the Linux Academy lab page) and get moving. Once we're in, create the directory and modify its permissions:

sudo mkdir /mnt/baserepo
sudo chmod 777 /mnt/baserepo

We can run chmod another way and get the same results:

sudo chmod a+rwx /mnt/basrepo

Clone the Remote Repository to the Local Location

We need to snag the remote repository at and get it into the recently created /mnt/baserepo directory. We can do it with these commands:

cd /mnt/baserepo
git clone .

Note: In this case, the . is very important since it will clone the repo contents to the directory we're sitting in (/mnt/baserepo). Without it, we'd end up with a repo clone in a new directory that matched the repository name.

Clone the Local Repository into Another Local One

We've got to clone that new local repo, because of that different project the dev is going to start off with. We want a new place for him to code, but don't want to touch the initial Git clone we created. We've got to get back to the dev's home directory first, make the new directory for the cloned clone, and then run git clone with a different option:

mkdir experiment
cd experiment/

git clone --local /mnt/baserepo .

Note: Remember again to use . in the cloning command, so that a new subdirectory is not created.


Well, we're done. The new developer has an official clone of the company's GitHub repo, and he's also got his own local clone of that so he can work on a separate project first. Congratulations!