Most common Git commands can be executed from the Android Studio user interface. Learn how to create new branches, commit changes, and merge changes from one branch into another.
- When you work with a project that's integrated with Git, you can commit new changes but you can also create new branches. Each branch can have a different version of the software. I'm not going to get deeply into all the ins and outs of Git in this course, but I will show you where some of the most important integration points are between Android Studio and Git. The project has to have already been set up as a Git repository. You can accomplish this either by sharing your own project or by cloning a project from, say, GitHub. Now let's say I wanted to make some changes but I want to create a new branch. So I can move back and forth between the two branches. There are a couple of places you can do this. One way is to go to VCS, and you should see a Git menu choice there, if the project has been integrated with Git. And then I can choose Branches. And that makes a dialogue appear. Now I can click New branch, and I can create a new branch by just giving it a name. I'll call this branch_number_2. Your branches can't have any spaces in the names. By default when you create the new branch, you'll be in that branch. And you see that in a couple of different places. You can go into the version control window, accessible here, or from the View/Tool Windows menu. It's right there. And there's a keyboard shortcut assigned to it. And there are a few different tabs here. There's Local Changes and if you make any changes you'll see them listed here. A log, showing everything that's happened in this repository. Pull Requests and Console. The Console is particularly useful because it shows you the raw Git commands that are being generated. This command for example, was used to create the new branch named branch_number_2. So now I'm going to make a change. I'm going to change the message that this host message displays, from Hello From Android, to This is branch 2. Now when I go to the Version Control window, I'll see that file listed, and I can press Command D on Mac, or Control D on Windows, to see the changes. Now I want to commit my changes. Again there are a few different places to do this. You can go to the VCS Git menu, and Commit from here. Or you can go to the tool bar and click on the Git icon, that's the check mark, or you can do the same thing in the Version Control window. I tend to use the Version Control window most, so that's where I'll work. I'll click the Commit button, and I'll set the Commit Message to a Change for Branch 2. And then if it's my own project or if I'm a contributor to that project, I can choose Commit and Push. But if I've checked out the project and it belongs to somebody else entirely, I would only commit to my Local Repository. I'll choose Commit and Push, because it's my project. I'll see the Push Commits dialogue, and I'll click the Push button. And now that change has been saved, both locally and at the remote depository on Git Hub. Now let's say I wanted to move back to the other branch. There's a couple ways to do that. I'll go to the menu and choose VCS Git Branches, and I can go to Local Branch Master, and check it out. And there's my original message. I can switch back again, with the same steps. I'll go to the Branches dialogue again, and this time I'll check out Local_Branch_2. You can also get to your branches from this menu that appears on the bottom status bar. It's exactly the same menu. Now, if you have a whole bunch of branches, this dialogue may look a little small. But you can click up here and expand the size of the menu, so you can see as many branches as you might have. So those are the beginnings of understanding how Git is integrated with Android Studio. There's a lot more functionality that you can do without having to work from the Command line in Git. You can go to the menu and choose Git, and see that you have options to Tag, Merge Changes, Stash and Unstash Changes, Clone, Fetch, Push, Pull, and so on. To learn more about Git, check out the courses in the library that teach you about working with Git from the Command line. And then explore what you can do in Android Studio directly from within the user interface.
- Installing Android Studio on macOS and Windows
- Creating your first project
- Creating virtual devices for testing
- Version control with GitHub
- Customizing the Android Studio interface
- Managing dependencies
- Generating and editing Kotlin code
- Refactoring and inspecting code
- Using templates
- Analyzing and debugging code
- Managing bitmap and vector images