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
Once you've cloned a repository, how do you keep the clone up to date with new commits? In this video, we'll show you how to pull commits from another repo.
When commits get added to a Git repository, they aren't automatically copied to clones of that repository. One way to distribute the new commits is to pull them in from other repos.
- In the original
medals
repo, save agold.html
file that advertises gold medals.
medals/gold.html
:
<h1>Check out our gold medals!</h1>
<p>Medallion: $60</p>
<p>Ribbon: $30</p>
- Stage the file with
git add gold.html
, and commit it:git commit -m "Add gold medals"
-
git log
in themedals
repo will show the new commit, butgit log
in themyclone
repo will not. - We need to get the commit that adds
gold.html
from themedals
repo to themyclone
repo.- To do that, we need a link from the
myclone
repo back to themedals
repo. - Within a Git repository, you can add links to other repos. These linked repos are referred to as remote repos.
- We can get a list of remote repos with the
git remote
command. - We see one remote repo listed here, named
origin
.
- To do that, we need a link from the
$ git remote
origin
When you clone a Git repo, the original repo is automatically added as a remote on the clone. You can name remote repos whatever you want, but the default used when cloning is origin
, because it represents the repo this clone originated from. Because of this default, you'll see a remote repo named origin
on most Git repos you work with. In fact, in many cases, the origin repo will be the only remote repo, because everyone on the project just pulls changes from that single repo.
- Since a remote repo is already set up, we're ready to pull changes from it.
- We do this with the
git pull
command. -
git pull
takes an argument, with the name of the remote repo you want to pull changes from. So this command will pull fromorigin
:
- We do this with the
git pull origin
- But just as the repo we cloned from was set up as a remote repo automatically, it was also set up as the default repo to pull from.
- So we can actually omit the remote repo name, and just run
git pull
:
- So we can actually omit the remote repo name, and just run
git pull
- Now, we can run
git log
within themyclone
repo. In the output we'll see the "Add gold medals" commit, just like we did in themedals
repo.
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