1 00:00:00,260 --> 00:00:04,350 Now you know how to use a remote branch to update a local branch. 2 00:00:04,350 --> 00:00:07,730 But what if you can't find a remote branch on your local repo? 3 00:00:07,730 --> 00:00:11,580 If we run git branch, we'll see that only the master branch is listed. 4 00:00:13,800 --> 00:00:16,690 We know there's an add-letter branch in the remote repo. 5 00:00:16,690 --> 00:00:18,660 Why isn't there one here? 6 00:00:18,660 --> 00:00:22,460 There actually is a remote branch named origin add letters, but 7 00:00:22,460 --> 00:00:25,770 it's not visible in the default git branch command. 8 00:00:25,770 --> 00:00:30,310 You can get a list of remote branches by adding the dash a flag to the git 9 00:00:30,310 --> 00:00:33,440 branch command, which causes it to list all branches. 10 00:00:34,660 --> 00:00:36,840 The output shows our one local branch, 11 00:00:36,840 --> 00:00:40,170 master, as well as all the remote branches. 12 00:00:40,170 --> 00:00:44,730 That includes the origin/master remote branch we were working with before. 13 00:00:44,730 --> 00:00:47,530 And we can see an origin add-letters branch here as well. 14 00:00:48,710 --> 00:00:51,240 To work with a remote origin/add-letters branch, 15 00:00:51,240 --> 00:00:54,640 we need to set up a local tracking branch for it. 16 00:00:54,640 --> 00:00:59,900 A tracking branch is a local branch with a direct relationship to a remote branch. 17 00:00:59,900 --> 00:01:03,270 Tracking branch is just the official terminology for it, though. 18 00:01:03,270 --> 00:01:07,250 Many developers just refer to tracking branches as local branches. 19 00:01:08,320 --> 00:01:12,290 When we clone the repository, the local master branch was automatically set 20 00:01:12,290 --> 00:01:15,940 up as a tracking branch for the remote origin/master branch. 21 00:01:15,940 --> 00:01:19,270 That's why we're informed whether we're up to date with origin/master 22 00:01:19,270 --> 00:01:22,810 when we run git status with the master branch checked out. 23 00:01:22,810 --> 00:01:25,980 We need to set up a local add letters branch in the same way. 24 00:01:25,980 --> 00:01:28,330 We do this by creating a new branch and 25 00:01:28,330 --> 00:01:31,320 specifying a remote branch it should track. 26 00:01:31,320 --> 00:01:33,430 There's several ways to do this. 27 00:01:33,430 --> 00:01:38,140 One is to use git checkout dash b just like creating any other local branch, 28 00:01:38,140 --> 00:01:42,070 except you add the remote branch that the local branch should track. 29 00:01:42,070 --> 00:01:43,420 So we could run get checkout dash b, 30 00:01:43,420 --> 00:01:46,981 have it create a local branch named add-letters, and 31 00:01:46,981 --> 00:01:51,410 specify origin/add-letters as the remote branch to track. 32 00:01:51,410 --> 00:01:54,860 This commit allows you to specify a tracking branch name that differs from 33 00:01:54,860 --> 00:01:56,284 the remote branch name. 34 00:01:56,284 --> 00:01:59,780 But 99% of the time, you're going to want them to be the same. 35 00:01:59,780 --> 00:02:00,848 So there are a couple of shortcuts. 36 00:02:04,209 --> 00:02:07,113 The first is to use the double-dash track option and 37 00:02:07,113 --> 00:02:09,760 skip specifying a local branch name. 38 00:02:09,760 --> 00:02:13,760 That will create a local branch with the same name as the remote branch. 39 00:02:13,760 --> 00:02:18,370 But there's an even shorter shortcut, and this is what developers use most often. 40 00:02:18,370 --> 00:02:20,800 If you run git checkout add-letters, 41 00:02:20,800 --> 00:02:25,050 git will look to see if there's a remote branch named add-letters. 42 00:02:25,050 --> 00:02:29,255 If there is, git will set the new local add-letters branch up to track the remote 43 00:02:29,255 --> 00:02:30,880 add-letters branch. 44 00:02:30,880 --> 00:02:32,510 You'll see this in the output. 45 00:02:32,510 --> 00:02:37,430 Branch add-letters set up to track remote branch add-letters from origin. 46 00:02:37,430 --> 00:02:39,170 When you create a tracking branch, 47 00:02:39,170 --> 00:02:43,430 it'll automatically be set to the same commit as its remote branch. 48 00:02:43,430 --> 00:02:46,840 If new commits are made to the add-letters branch in the remote repo, 49 00:02:46,840 --> 00:02:48,780 they won't automatically be brought over. 50 00:02:49,800 --> 00:02:53,630 Just like we saw in the previous video, you'll need to use git fetch to update 51 00:02:53,630 --> 00:02:56,590 the origin add letters remote branch with the new commits. 52 00:02:56,590 --> 00:03:01,900 And then use git merge to merge the commits into the local add-letters branch. 53 00:03:01,900 --> 00:03:06,040 We did mention there was an easier way to get commits from remote repos, though. 54 00:03:06,040 --> 00:03:08,670 We'll look at the git pull command in the next video.