Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Git Branches and Merging!
You have completed Git Branches and Merging!
Preview
A local tracking branch is one that's associated with a remote branch. There's an advantage to establishing this association. It lets you use the `git pull` command when that tracking branch is checked out.
- Remember that a local tracking branch is one that's associated with a remote branch.
- There's an advantage to establishing this association. It lets you use the
git pull
command when that tracking branch is checked out. - The
git pull
command is like runninggit fetch
followed bygit merge
. It lets you retrieve remote changes and incorporate them into your local tracking branch with a single command. - With
git pull
, you don't have to specify which remote you want to fetch from, or which remote branch you want to merge in, because all of that info is stored by the tracking branch. Your tracking branch will always fetch from the same remote repo, and merge in the same remote branch. - You just type
git pull
, and hit Enter. Git will do the rest:git pull
- Right now, there are no commits in the remote repo's
add-letters
branch to pull over, so it says we're "Already up to date."
- Right now, there are no commits in the remote repo's
$ git pull
Already up to date.
- Let's go back to the remote repo and add a commit:
cd ../decoder
- And I'll check out the
add-letters
branch:git checkout add-letters
- I'll add another conversion to the
decoder.rb
file:
11 => 'K',
- I'll stage it:
git add decoder.rb
- And commit it:
git commit -m 'Add K conversion'
- Now let's go back to our local repo:
cd ../decoder-local
- And run
git pull
again:git pull
- The output looks just like what you'd see if you did a
git fetch origin
followed by agit merge origin/add-letters
.
- The output looks just like what you'd see if you did a
$ git pull
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From /Users/jay/th/decoder
af94e11..09d6fcb add-letters -> origin/add-letters
Updating af94e11..09d6fcb
Fast-forward
decoder.rb | 1 +
1 file changed, 1 insertion(+)
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
Remember that a local tracking
branch is one that's associated with
0:00
a remote branch.
0:03
There's an advantage to
establishing this connection.
0:05
It lets you use the git pull command when
that tracking branch is checked out.
0:07
The git pull command is like running
git fetch followed by git merge.
0:12
It lets you retrieve remote changes and
0:17
incorporate them into your local
tracking branch with a single command.
0:19
With git pull, you don't have to specify
which remote you want to fetch from, or
0:23
which remote remote branch
you want to merge in,
0:27
because all of that info is
stored by the tracking branch.
0:29
Your tracking branch will always
fetch from the same remote repo, and
0:33
merge in the same remote branch.
0:37
You just type git pull and
hit Enter, git will do the rest.
0:39
Right now, there are no commits in
the remote repose add letters branch to
0:43
pull over.
0:47
So it says, we're already up to date.
0:48
Let's go back to the remote repo and
add a commit, cd ../decoder.
0:50
And I'll check out the add letters branch,
git checkout add-letters.
0:56
Now I'll add another conversion
to the decoder.rb file.
1:02
Again, I'm editing the original repo,
The one that we're treating as a remote.
1:07
And I'll add this conversion in
from the number 11 to the letter K.
1:13
I'll go back to my terminal and
stage this.
1:18
And I'll commit it,
git commit -m Add K conversion.
1:22
Now let's go back to our local repo,
cd ../decoder-local.
1:30
And I'll run git pull again.
1:37
This time, the output looks just like what
you'd see if you did a git fetch origin
1:40
followed by a git merge
origin/add-letters.
1:44
It fetches all the new commits from the
remote repo and updates the remote branch.
1:48
And then it merges the remote branch
into the local tracking branch.
1:55
All of that with one command.
1:59
Some git users encourage explicitly
fetching and merging instead of using git
2:02
pull, saying that git pull hides
what it's doing from the user.
2:06
And I think that makes sense if you're
working with multiple or remote
2:10
repositories, or merging several different
remote branches into your local branch.
2:13
But personally,
2:18
on the projects I've worked on,
I've only ever had one remote repo.
2:19
And I only merge one remote
branch into each local branch.
2:23
So git pull works just fine for me,
and it saves me a lot of typing.
2:27
But you should use whichever commands
make sense for your environment.
2:31
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