Git in the IDE
Android Studio 2: The New UI
Course 2 ยท Chapter 10 ยท Git in the New UI
Git saves the history of your project so you can undo, compare and share it. Android Studio has Git built in, and the New UI changes what you see depending on whether the project has a repository yet. This chapter shows both states, the two tool windows you will use most, and a few commit habits.
Before a Repository: VCS
In a project with no repository the menu bar says VCS, and the top toolbar shows a Version Control widget beside the project name (checked on the install). (docs) From the VCS menu choose Enable Version Control Integration, pick Git as the system for the project root and click OK. Version-control settings are also under File > Settings > Version Control.
After a Repository: Git
| Item | Before a repository | After a repository |
|---|---|---|
| Menu bar | VCS | Git (replaces VCS) |
| Toolbar widget | Version Control | The current branch name (master in the project checked) |
The Commit Window (Alt+0)
On the left bar. It lists the changed files with checkboxes, has an Amend last commit option, a message box, Commit and Commit and Push... buttons, and a gear for options (all checked on the install). Tick the files that belong together, write the message and commit. (JetBrains docs, not checked here) New files start under Unversioned Files and are added by ticking them.
Habit: in the screenshot the commit message was typed as "initial commit" with the quote marks. The IDE does not need them; they become part of the message. Write a short plain sentence,
say what changed and why, and keep one idea per commit.
The Git Window (Alt+9)
At the bottom. It has Log and Console tabs, a branch tree (HEAD, Local, Remote), a search for text or a hash, and filters for Branch, User, Date and Paths (checked on the install).
In that project the log showed origin & master, meaning the project already pointed at a remote. The Log tab is where you read history; the Console shows the Git commands the IDE ran.
Remotes and Pushing
A remote is a copy on a server such as GitHub, usually named origin. Two routes are possible: make the repository in the IDE first and add a remote later, or create the repository on GitHub first and
clone or connect it. (JetBrains docs, not checked here) Other JetBrains IDEs push with Git > Push or Ctrl+Shift+K, which lists the commits before sending them; Commit and Push... does both
in one step. Some JetBrains IDEs can also create a GitHub repository from the VCS or Git menu; I could not confirm that for Android Studio, so check the menu yourself. If you prefer the command line, the Terminal window (Alt+F12) runs the same commands:
.gitignore normally excludes local.properties and build folders (general knowledge). Check it before the first push, and never commit passwords or API keys.
Try It Yourself
In a scratch project with no repository, note the menu name and toolbar widget. Use VCS > Enable Version Control Integration with Git, then note what changed in the menu bar and the widget.
๐ View solutionOpen the Commit window (Alt+0), tick your files, commit with a message that has no quote marks, then open the Git window (Alt+9) and find your commit in the Log tab.
๐ View solutionSearch the Git menu for any command that creates or shares a repository on GitHub and report its exact name, or say there is none. Then create a branch and switch back to master using the toolbar widget.
Checked in the docs (one web search): Android Studio's Enable Version Control Integration and the Settings path.
From other JetBrains IDEs only: unversioned-file handling, Git > Push and Ctrl+Shift+K.
Not verified: Share Project on GitHub or any GitHub menu item; the toolbar widget's branch menu (Exercise 3); the
.gitignore contents; the exercises (not run by me).
A screenshot of the Git menu open (after a repository exists) and the branch widget's drop-down would verify this chapter.Sources: Version control basics (developer.android.com), Tutorial: Getting started with Git in GoLand (jetbrains.com).