Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In this movie we are going to learn how to check out remote branches. First, I want you to notice that I am inside my lynda_ version directory, and I am on the master branch. If I do git branch, you will see that's the only branch that I have in this Lynda repository, and if I do git branch with the -r option to look at the remotes, you will see that there is also this non tracking branch out there. What I want to do is be able to have that non tracking branch where I can work with it. Someone posted up there, I want to see what it is. I want to see what code they have put in there, bring it down, maybe I can make some additions to it and then push it back up there again.
Now you may remember in the last movie, I told you that these remote branches are exactly like regular branches with one exception, and that's that we can't check them out. That makes sense because Git stays in control of that remote branch so it can make sure it always stays in sync with what's in the remote repository. It doesn't want us getting in the way. But since it is just like every other branch, we can create a branch from it that we can then work with; git branch and then our new branch name, non_tracking.
After that we can tell it where we want the non _tracking branch to come from, the starting point of this branch. Now in the past, we just used the default for that which is HEAD, which points to the tip of the current branch master. But you can specify other things here. You can specify a particular commit or we can specify origin/non_tracking. So there it is, git branch non_tracking, origin non_ tracking, this will create that branch for us. Let's go ahead and check that out, you can see branch non_tracking set up to track remote branch non_tracking from origin.
It created it, and it's a tracking branch. It's going to track this. That's what that syntax does for us. Now if I do git branch, you will see that I have that non_tracking branch, and if I take a look at my git/config file, you can see that it has set it up so that non_tracking will track origin/non_tracking. Okay, the next thing I want to show you is I want to delete that branch, we remember how to do that, git branch -d non_tracking, now that branch is gone, again, that's my version, that has nothing to do with what's on the remote repository, has nothing to do with what's in origin/master, those are still there, git branch -r, but what I want to do is I want to show you that you also can do git checkout with the -b option. Remember, this is create a branch and check it out, all in the same step, or check it out as a new branch.
Let's say non_tracking and origin/non_tracking. So it's that easy for us to get a copy of the non_tracking branch. So now we are on the non_tracking branch, we can make commits here and then when we do a push, those will be pushed up to remote repository non_tracking. If we want to switch back to master, git checkout master. Now we are on the master branch, and we can make changes here, when we finally are ready, we can say push and those will also go to the remote repository.
If we do fetch, it will get all of our origins and sync with what's in the remote repository, and then we can merge in. Hopefully, now you are starting to get the sense of the flow of how we fetch and pull and work with these different branches.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 101478 Viewers
61 Video lessons · 88242 Viewers
71 Video lessons · 72114 Viewers
56 Video lessons · 103875 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.