If you're comfortable using Git in Android Studio, you can check out the repository once. Each exercise has two branches, one for the starting and one for the ending state. I'll describe how to check out each branch as you need it.
- [Instructor] I previously described how to work with the GitHub repository for this series of Weekly Tips without having to sign into GitHub at all by simply downloading a Zip file for each exercise as you need it. But if you're acquainted with Git or you want to simply get used to working with Git in Android Studio you can instead use the integration of GitHub and you'll find that it's a lot simpler and faster than downloading each Zip file individually. First, you'll need to have installed Git and you can download it from git-scm.com.
If you're working on Windows, this is definitely the best place to get it and if you're working on Mac you might go to the terminal and type Git and see if it's already installed. Either way, follow the instructions here to download and install Git on your system and if you have any questions about it, take a look at the course, Git Essential Training. Next, in Android Studio you need to configure your GitHub installation. From the Welcome screen you can go to Settings on Windows or Preferences on Mac.
Click on Version Control, and open up that tree, and click GitHub, and enter your GitHub Login information, your Login ID, and your Password. If you're using two-factor authentication there might be a few more steps but you'll already be acquainted with that if you're using it and then Test to make sure that Android Studio can connect to GitHub. If you have any issues on these steps watch the section in the course, Android Studio Essential Training that talks about GitHub integration.
Once you've done those steps you're ready to download the Git repository but you can do it now from the Welcome screen. I'll go back to the Git repository on the web and I'll make sure that I'm at the root of the URL, that is, I'm looking at the master Branch. I'll click Clone or download and then I'll click the Copy to clipboard button to copy this URL to the clipboard. Now, I'll go back to Android Studio's Welcome screen and I'll choose Check out project from Version Control and then I'll choose GitHub.
I'll then paste in that URL and that will automatically create a new Directory called Weekly Tips and by default it'll be under, AndroidStudioProjects, under my home Directory. You can, however, place it anywhere on your hard disk you like. I'll click Clone and that results in downloading the master Branch of the repository. Now, I'll open the project in Android Studio. Just as when I downloaded a Zip file, I'm prompted to upgrade my Gradle Plugin and I'll click Update.
If you see a File Cache Conflict click on Load File System Changes and then you might see this dialog again and just keep on clicking Update until it's accepted. Wait then until the Gradle built process is complete and if you see any other offers to upgrade various components of the Android SDK accept those offers and follow the prompts to complete the downloads. Once all the build process messages are gone you're ready to test the application.
Now, I've downloaded the master Branch and this is how you'll know that you're looking at the master Branch of the exercise files. When you run the application on your device you'll get this message, indicating that this is the master branch and reminding you that to use a particular exercise for a tip check out that branch and here's how you would do it. I'll go back to Android Studio and I'll go to the menu and choose VCS + Git + Branches.
You'll see a whole bunch of Remote Branches listed here and if for any reason you don't see the Branch you're looking for click away from this dialog to close it, then choose VCS + Git, again, and then choose Fetch and that will download records of all the Branches that are up on the website. Now, I'll go once again to VCS + Git + Branches and I'll choose the Branch for the starting state of the first Tip and I'll choose Checkout as new local branch.
When prompted, I'll accept the name of the new branch and click OK, then I'll run the application on the device again, that rebuilds the application and now I see the message that this is the sample app for tip number one. If you want to look at the finished state of any particular Branch check that out. I'll go to VCS + Git + Branches and this time I'll choose Tip001-Done, that's the completed state, and I'll check it out as a new local branch, and then when prompted I'll accept the name, and then I'll run the application again, and this time when I click Run Code I get a snackbar message because that's what I teach you how to do in this particular Tip.
Here's one more thing about working with Git, let's say you made a change to some file in your application, I'm going to switch back to the beginning state of the first exercise by selecting Git + Branches and then I'll choose the first Tip Branch from the Local Branches and I'll check it out. Now, I'll open the file strings.xml, I pressed the Shift key twice and typed in the name of the file and I'll just make any change at all.
Now, when I go to my Version Control window down here, I see these changes that have been made. Now, watch what happens when I try to check out another Branch. I'll select VCS + Git + Branches and I'll try to switch to the Done Branch. Now, if at this point you see a prompt telling you you can't do that Checkout here's what you need to do, switch back to the Branch that you were working on. I'll go back to Tip01 and then Commit the Changes.
Over here you can see a Commit Changes button and when prompted type in any Commit Message at all, My changes to tip one, for example, and then click the Commit button and choose Commit. You don't need to Push because you won't be Pushing your changes to the Remote repository. Now, you shouldn't have any trouble checking out a New Branch. So that's how you work with the GitHub repository from within Android Studio.
Down here at the bottom you'll always be able to see which is your Current branch and you'll be able to Checkout Remote Branches and download them to your system by simply selecting them from the bottom list and then choosing Checkout as new local branch.
Skill Level Intermediate
Q: Why can't I earn a Certificate of Completion for this course?
A: We publish a new tutorial or tutorials for this course on a regular basis. We are unable to offer a Certificate of Completion because it is an ever-evolving course that is not designed to be completed. Check back often for new movies.