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
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 themaster
branch is listed:git branch
- We know there's an
add-letters
branch 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 defaultgit branch
command. - You can get a list of remote branches by adding the
-a
flag togit 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-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. - 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 namedadd-letters
. - If there is, Git will set the new local
add-letters
branch up to track the remoteadd-letters
branch.
$ 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-letters
branch 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 fetch
to update theorigin/add-letters
remote branch with the new commits, and then usegit merge
to merge the commits into the localadd-letters
branch.
There's an easier way to get commits from remote repos, though. We'll look at the git pull
command in the next video!
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