Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
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(+)
-
0:00
Remember that a local tracking branch is one that's associated with
-
0:03
a remote branch.
-
0:05
There's an advantage to establishing this connection.
-
0:07
It lets you use the git pull command when that tracking branch is checked out.
-
0:12
The git pull command is like running git fetch followed by git merge.
-
0:17
It lets you retrieve remote changes and
-
0:19
incorporate them into your local tracking branch with a single command.
-
0:23
With git pull, you don't have to specify which remote you want to fetch from, or
-
0:27
which remote remote branch you want to merge in,
-
0:29
because all of that info is stored by the tracking branch.
-
0:33
Your tracking branch will always fetch from the same remote repo, and
-
0:37
merge in the same remote branch.
-
0:39
You just type git pull and hit Enter, git will do the rest.
-
0:43
Right now, there are no commits in the remote repose add letters branch to
-
0:47
pull over.
-
0:48
So it says, we're already up to date.
-
0:50
Let's go back to the remote repo and add a commit, cd ../decoder.
-
0:56
And I'll check out the add letters branch, git checkout add-letters.
-
1:02
Now I'll add another conversion to the decoder.rb file.
-
1:07
Again, I'm editing the original repo, The one that we're treating as a remote.
-
1:13
And I'll add this conversion in from the number 11 to the letter K.
-
1:18
I'll go back to my terminal and stage this.
-
1:22
And I'll commit it, git commit -m Add K conversion.
-
1:30
Now let's go back to our local repo, cd ../decoder-local.
-
1:37
And I'll run git pull again.
-
1:40
This time, the output looks just like what you'd see if you did a git fetch origin
-
1:44
followed by a git merge origin/add-letters.
-
1:48
It fetches all the new commits from the remote repo and updates the remote branch.
-
1:55
And then it merges the remote branch into the local tracking branch.
-
1:59
All of that with one command.
-
2:02
Some git users encourage explicitly fetching and merging instead of using git
-
2:06
pull, saying that git pull hides what it's doing from the user.
-
2:10
And I think that makes sense if you're working with multiple or remote
-
2:13
repositories, or merging several different remote branches into your local branch.
-
2:18
But personally,
-
2:19
on the projects I've worked on, I've only ever had one remote repo.
-
2:23
And I only merge one remote branch into each local branch.
-
2:27
So git pull works just fine for me, and it saves me a lot of typing.
-
2:31
But you should use whichever commands make sense for your environment.
You need to sign up for Treehouse in order to download course files.
Sign up