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

Commit local branch changes - GitHub Tutorial

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

Commit local branch changes

- [Instructor] After making changes to files in a GitHub branch, you should commit or save them locally before switching to another branch. Now, there are two kinds of commits that I'll recommend. When you're working in IntelliJ IDEA, there's a lot of configuration files. And if an instructor created a course using an older version of IntelliJ IDEA, when you open each branch, IDEA will make changes or even create new files. So each time you open a branch before you do any code changes, I recommend committing those changes. Go to the commit window and select all the files you see there. Set your commit message to something like "Saving config file changes," and click commit. Now you have a clean change list, and now you can add new code. I'm going to duplicate this line of code, and I'll change it once again to choiceFour = "pluto." And as I make that change, I'll see my change list now includes new files. Once again, here's another configuration file that IntelliJ IDEA has changed on the fly for me. I'll click that and I'll commit that. And now I'm just down to my code files. Now, I'll change my commit message to "Saving my changes to code," or something like that. I'll select all the files that are code based, and I'll click commit. When you're dealing with code, each time you make a commit, IntelliJ IDEA will analyze your code, and if it sees issues, it'll tell you. If you like, you can review IntelliJ IDEA's suggestions. For example, here, it's saying something about an array declaration of parameter args. I don't care about that. And here we're saying that there's a local variable called correctAnswer that's redundant. If you want, you can make changes to fix those issues, or you can go to the code and then use an intention action. Press Alt + Enter on Windows or Option + Return on Mac. Press the right arrow to see the available options and suppress that issue. This is called a lint suppression annotation. And it means don't worry about this issue. Now I'll come back to my commit window, and once again, I'll click on commit. This time I see one warning found, and I say that's all right. I know about that warning and I'm not going to worry about it. I'll click commit and my changes have been saved locally. And now I can safely switch to any other branch knowing I can come back to this branch and see this state of the code anytime I want to. So that's how you can navigate between different branches, rolling back your changes to the original state within a branch, or committing changes, both for changes to your configuration files that IntelliJ IDEA is making for you in the background and for your own code changes.

Contents