Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
We were able to successfully create a remote GitHub repository and to configure our local repository so that we can push all of our local commits up to the remote. Now I want to switch gears for a second, and I want us to do the opposite. And that is instead of taking a repository that's local and pushing it to the remote, I want to see how we can do the reverse. How we can go with a remote repository and pull it down to have a local copy of it to work with. This is assuming that we don't have a local copy to start with. This kind of circumstance would come up, if someone said, hey come and collaborate on a project with me.
I have put my code on GitHub, now why don't you go get it, pull down a copy, and then we could start collaborating. Or if you wanted to work on open-source project, the same kind of thing. You'd go out, find the open-source project, get a copy of it to bring on to your local machine, and then you could start contributing. The way we will simulate this on our single machine is that we will back out of our Explore California directory. So I'm going to cd.., go backwards a directory, and in that directory you can see I have got my explore_california. I'm just going to ignore that. Let's pretend it doesn't even exist for a moment.
Let's say that I'm a brand new user, I've got Git installed, but I don't have a Git project yet on my machine. What I want to do is go to GitHub and figure out what project I want. Now you can search around, and you click the Explore link, and you can look for different open-source projects, or we can stumble upon this Explore California web site and say, all right, I'm going to collaborate on that one. Regardless of how you get to the project, what you need to know is, how do you locate it? And GitHub tells you that information right here. This is what you need to know. So you want to copy this so that we can paste it.
This is the path to the repository. It's also the same path that got configured in our Explore California folder, when we set up the remote branch. It's the way that we refer to this repository. So let's take that over here, and now from the command line, notice I'm not in any kind of Git project at the moment, I'm just in a plain old folder. I'm going to say git clone, and then I'm going to paste in that path. So I'm going to clone that remote repository which basically it's going to say, make me a local copy of it, clone it on my machine.
And what it does, it's going to create a new directory, and that directory by default will be the name here, explore_california, not the .git. So explore_california is the default. Now of course, I already have an Explore California folder, so when I try it, it says sorry that already exists. But that's no big deal. We can call the folder that exists in, anything we want. The name of the directory has nothing to do with the name of the repository. So let's give it a different name. I'm going to say that I'm going to be collaborating with Lynda, so I'm going to call this lynda_version.
So this is Lynda's version of the repository. So you can see when I do that, it counts the objects, and it compresses them, and it receives them on to my local machine. Now I do ls -la, you will see I have got this new folder, lynda_version. Let's go inside that folder, take a look, and there's my whole project. It downloaded the files and folders around GitHub to my local repository. Now we do git branch, you'll see that we don't have all of the branches that we had in our own version, in the explore_california version, instead we just have the master branch because that's all that exists on the remote branch.
Those other ones that have never been pushed up there, they remain private until we push them up there and make them public. Now if there had been more than one branch up there, it still would have brought down the master branch by default. You can specify the -b option and tell it which branch you want, if you want a different one, but by default it's going to take whatever GitHub has as its default branch, and by the way, you can also configure which branch is the default in GitHub, in the GitHub admin controls. So now we successfully cloned this project on to our machine. Our machine happens to have two repositories on it.
And what I'm thinking is that we're going to able to switch back and forth between those, as if we were actually jumping from one computer to another computer. They just happen to exist on the same computer, but it's two different git repos. We're going to call one of them our version and the other one will be Lynda's version, and Lynda is going to be a collaborator that we are going to work with on this project. So we will make commits, we will push them up to the remote, and then we can switchover to Lynda's repo and see how it looks to her. Then she can make changes, push those up to the repo, and we can switch back to our version, we will be able to see things from our side and how they would look.
So don't let it throw you that it's not actually two different people on two different computers, it's still two different Git repositories each that contain their own unique sets of information.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 98498 Viewers
61 Video lessons · 85793 Viewers
71 Video lessons · 69692 Viewers
56 Video lessons · 102007 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.