Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
Before you can "push" commits to another repository, you need to add it as a remote repo.
Update
Add to myclone/medals.html
:
<div>
<a href="gold.html">Gold medals</a>
</div>
<div>
<a href="silver.html">Silver medals</a>
</div>
- Then stage the changes:
git add medals.html
, and commit them:git commit -m "Add links"
- That commit now appears in our history for the
myclone
repository.
- That commit now appears in our history for the
- But this commit does not appear in the
medals
repository. - Although we were able to run
git pull
in themyclone
repository to pull in commits from themedals
repository, we can't pull frommyclone
tomedals
yet. - When we cloned the
medals
repository to themyclone
repository,medals
was automatically set up as a remote repo onmyclone
.- But the reverse isn't true. In fact, we can try running
git remote
from themedals
repo, and we won't see any remote repos at all.
- But the reverse isn't true. In fact, we can try running
- So we're going to need to add
myclone
as a remote on themedals
repo.- We can do this with the
git remote add
subcommand. -
git remote add
takes two arguments: - The first is the name we want to give the remote repo. We can use any name we want, but generally, it should be all lowercase. We'll use the name
myclone
for this remote. - The second argument will usually be the URL of the remote repository.
- But since this "remote" repo is just another directory on our local computer, we'll give it the path to that directory instead:
../myclone
- But since this "remote" repo is just another directory on our local computer, we'll give it the path to that directory instead:
- We can do this with the
git remote add myclone ../myclone
- Now let's try running
git remote
again. This time, we'll see a remote repo with the name we specified,myclone
. - For this first-time running
git pull
, we need to provide two arguments:- The remote repo we're pulling from:
myclone
- The "branch" we want to pull:
main
| UPDATE - Renaming the default branch frommaster
tomain
. - By default, Git repositories start with only one branch, named
main
. - Because we haven't created any other branches, our work in the
myclone
repo will be on themain
branch there, as well.
- The remote repo we're pulling from:
git pull myclone main
- That command will pull our new commit from the
myclone
remote repo into 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
This time, we've made a change not in the
medals repo but in the myclone repo, so
0:00
let's change to that directory,
cd myclone.
0:04
Now let's take a look at what's changed,
git diff.
0:09
We realize that there was
no link to the gold.html or
0:12
the silver.html pages from the main page,
so we added links and saved the file.
0:15
Let's stage the changes,
git add medals.html,
0:21
and now let's commit them,
git commit -m "Add links".
0:27
That commit now appears in our history for
the myclone repository.
0:34
If we run git log,
we'll see the add links commit at the top.
0:37
Now as you might anticipate
from seeing the previous video,
0:43
this commit does not appear
in the medals repository.
0:46
Let's change to the parent directory, and
then back down to the medals subdirectory.
0:50
Now that we're in the medals repo,
let's run git log, and
0:56
there's no add links commit here.
1:00
And although we were able to run git pull
in the myclone repository to pull in
1:03
commits from the medals repo,
we can't pull from myclone to medals yet.
1:08
If we run git pull myclone,
we'll get the error,
1:12
myclone does not appear
to be a git repository.
1:19
When we cloned the medals repository
to the myclone repository,
1:23
medals was automatically set up
as a remote repo on myclone.
1:27
But the reverse isn't true, in fact,
1:31
we can try running git
remote from the medals repo.
1:33
git remote, and
we don't see any remote repos at all.
1:36
So we're going to need to add myclone
as a remote on the medals repo.
1:42
We can do this with the git
remote add command.
1:47
git remote add takes two arguments,
1:51
the first is the name we want
to give the remote repo.
1:54
We can use any name we want, but
generally it should be all lowercase.
1:57
In the myclone repo,
2:01
a default name of origin was used
to refer to the medals repo.
2:03
Medals wasn't cloned from myclone, though,
so that's probably not appropriate here.
2:06
Instead we'll just give it the same name
as the directory we cloned it to, myclone.
2:12
The second argument will usually be
the URL of the remote repository.
2:19
Since this remote repo is just another
directory on our local computer,
2:24
we'll give it the path to
that directory instead.
2:28
We can't just type myclone, though,
2:32
that would indicate the myclone directory
lives inside the medals directory.
2:34
We need to indicate the myclone
directory that lives alongside
2:40
the medals directory in
the parent directory.
2:43
So we type .., for
the parent directory, /myclone.
2:45
You can read that as the parent
directory's myclone subdirectory.
2:51
Okay, so we have a name for
2:56
the remote repo as well as the directory
path that we're using in place of a URL.
2:57
Let's hit Enter to run the command.
3:02
We won't see any output, but as usual,
that just means there were no errors.
3:04
Now let's try running git remote again.
3:09
This time we'll see a remote repo
with the name we specified, myclone.
3:12
So now we have a remote repo set
up in the medals repo as well.
3:17
Let's see if git pull works this time.
3:21
git pull, we still get a no remote
repository specified error.
3:23
Let's try specifying the remote
repository name, git pull myclone.
3:29
We get an error again, but it's not
myclone does not appear to be a git
3:36
repository, so at least this is progress.
3:40
The error says we didn't
specify a branch to pull from.
3:43
We won't be covering git branches
in this introductory course.
3:47
But you can see the teacher's notes
if you'd like more info about them.
3:51
We have to specify a branch name to
get this command to work, though.
3:55
You can get the current branch
name with the git branch command.
3:58
By default, git repositories start
with only one branch, named master.
4:04
Because we haven't created
any other branches,
4:09
our work in the myclone repo will be
on the master branch there as well.
4:12
So let's specify master as the branch name
to pull from, git pull myclone master.
4:16
That took a lot of setup, but
our command finally worked.
4:28
It pulls our new commit from the myclone
remote repo into the medals repo.
4:31
If we run git log,
we'll see the Add links commit at the top.
4:36
And if we run git log -p, it will show the
actual changes to the medals.html file.
4:42
So now you know how to
add a remote repo in git.
4:50
That's going to be important,
4:53
because the next remote you add
is going to be a GitHub repo.
4:54
We'll show you how to share your
work on GitHub in the next video.
4:58
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