From the course: Working with LinkedIn Learning Exercise Files on GitHub

Checkout and switch branches - GitHub Tutorial

From the course: Working with LinkedIn Learning Exercise Files on GitHub

Checkout and switch branches

- [Instructor] After cloning a project from GitHub, you can work with it in many ways in IntelliJ IDEA. The first step is to get to know your branch structure. Each branch in Git has a beginning state. You can see your list of branches in a couple of different places. As I showed previously, there's a branch list that pops up from the bottom here, and you can expand this window upward so you can see more information. You'll see local branches and remote branches. You can also see that list by going to the menu and choosing, Git, branches. And you'll see exactly the same information but this time in a pop-up window. When you click off the window, it disappears. And then finally, you can also see these branches in the Git window that appears down at the bottom of the screen. To use a particular branch, check it out. So for example, I'm going to go deep into this course to chapter four and I'm going to choose the beginning state of chapter four, video number two, and I'll right click on it and I'll choose checkout. If you see this message saying that untracked files prevent checkout, click on view files and you may see a listing of files that have been generated since you opened the repository. This happens a lot in IntelliJ IDEA. If that happens, make a mental note of these files, click okay, and then go to your commit window. Open up your list of unversioned files here and you can choose which files you want to save locally. So for example, I'll choose the mis and modules files, I'll add in a commit message, saving files locally. You could put in any message you like and then I'll check the files that I want to save and I'll click commit. Those files now become a part of your local version of the repository. Don't click commit and push because you won't have rights to save things in the course repository on GitHub. I'll do the same thing with this .git ignore file. I'll select it by checking the check box and clicking commit. And now those files changes have been saved locally and I should be able to check out another branch. I'll come back over here again, right click and choose checkout. And then I'll click on my project window and I'll see that my folder structure has changed. And again, this is unique for this particular course. I'll click the source directory and then open up the main class and I'm ready to work with this content. If I want to switch to yet another branch, I can do that also from this menu. I'll click on my branch list. And this time I'll choose 404B, I'll click it and click checkout. And now I'm on that version of the code. Each time you check out a branch, you're making a local copy of the branch on your local hard disk. And then if you go to your branch list over here, you'll see that those branches are listed now under local. The main thing to remember is that whenever you want to check out a new branch, you need to have saved your changes or committed them in the branch you've been working on. And I'll talk a little bit more about committing and rolling back changes later.

Contents