Local Tracking Branches3:09 with Jay McGavren
To work with the remote `origin/add-letters` branch, we need to set up a local __tracking branch__ for it. A tracking branch is a local branch with a direct relationship to a remote branch.
Now you know how to use a remote branch to update a local branch. But what if you can't find a remote branch on your local repo?
- If we run
git branch, we'll see that only the
masterbranch is listed:
- We know there's an
add-lettersbranch in the remote repo. Why isn't there one here?
- There actually is a remote branch, named
origin/add-letters. But it's not visible in the default
- You can get a list of remote branches by adding the
git branch, which causes it to list all branches:
$ git branch -a * master remotes/origin/HEAD -> origin/master remotes/origin/add-letters remotes/origin/master
- To work with the remote
origin/add-lettersbranch, we need to set up a local tracking branch for it. A tracking branch is a local branch with a direct relationship to a remote branch.
- We do this by creating a new branch, and specifying a remote branch it should track.
- If you run
git checkout add-letters, Git will look to see if there's a remote branch named
- If there is, Git will set the new local
add-lettersbranch up to track the remote
$ git checkout add-letters Branch 'add-letters' set up to track remote branch 'add-letters' from 'origin'. Switched to a new branch 'add-letters'
- When you create a tracking branch, it will automatically be set to the same commit as its remote branch.
- If new commits are made to the
add-lettersbranch in the remote repo, they won't automatically be brought over.
- Just like we saw in the previous video, you'll need to use
git fetchto update the
origin/add-lettersremote branch with the new commits, and then use
git mergeto merge the commits into the local
There's an easier way to get commits from remote repos, though. We'll look at the
git pull command in the next video!
You need to sign up for Treehouse in order to download course files.Sign up