Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
The "git clone" command can copy a repository, along with its full commit history, to another computer.
Using clones as peers
- With Git, every developer has their own repository on their machine, called their local repo.
- Repos belonging to other developers on the project are referred to as remote repos.
- Each repo is a full copy of the original repo, including all the version history.
- Developers can make commits to their own repo, independently of the others.
- Before beginning work on a new feature, you should use the network to pull commits other developers have made from a remote repo into your local repo, so that you have the latest version of the code.
- Then you can make your changes, and commit them to your local repo.
- Other developers will be able to pull the commits you've made over the network to their clones, so they can access them.
Pushing to a central repo
- Any Git repository is capable of pulling from any other repo. Sometimes collaborators pull from each other's repos directly.
- But it's more common to declare one repo the "central" repo.
- Developers clone this central repo to their local machines over the network.
- Then, each developer begins working on their own separate set of changes.
- A developer adds their changes to this central repo by pushing commits to it over the network. *Other developers receive these commits by pulling them down from the central repo, and they can push up their own changes in return.
- This is the system that GitHub, Bitbucket and other Git hosting services support.
Cloning repos
The easiest way to get a new repo based off another is to clone it, to make a copy of it. This copy will have all the same files in the working directory, plus a full copy of the project's history.
Normally you clone from one computer to another over the Internet or some other network. But we can also clone from one directory to another on the same computer, and everything will work the same. We're going to do that while we get used to the commands.
To clone the medals repo to a repo in another directory named myclone
, change to its parent directory and run:
git clone medals myclone
- The first argument to
git clone
should be the location of the repository you want to clone. Normally, this would be the URL of a repo out on the network somewhere. But for this demonstration, we just clone from themedals
repo in our local directory. - The second argument is the name of the directory you want to clone into. We used the name
myclone
. - If we run
ls
, we'll see a newmyclone
directory.- We can change into that with
cd myclone
. - If we run
ls
here in the working directory, we'll see copies of all our files. - Remember
ls -a
shows all files, even ones that are hidden by placing a dot at the start of their names... If we run it here, we'll see another.git
directory that holds a copy of our repo history.
- We can change into that with
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up