Developing applications for mobile devices is impossible without a reliable version control system. Android Studio offers excellent integration with Git by default, but manual configuration or installation of additional plugins is often required for full functionality. If you are just starting your development journey, correctly connecting the repository will be the foundation of your future work.
Many beginners are faced with the fact that the IDE does not see Git installed in the system, or they have difficulties with authorization on GitHub or GitLab. This happens because the paths to the executable files may not match, or the environment variables are not configured correctly. In this article, we will take a detailed look at the integration process so that you can focus on the code and not on finding configuration errors.
We will look not only at the basic installation, but also the intricacies of working with VCS (Version Control System) inside the development environment. You'll learn how to check connection status, create your first commit, and set up remote storage. Proper setup at the start of the project will save you hours of troubleshooting in the future.
Preparing the environment and installing Git
Before moving on to the settings inside Android Studio, you need to make sure that Git itself is correctly installed in your operating system. For Windows users, the best solution is to download the official installer from git-scm.com, which automatically adds the necessary paths to the environment variables. On macOS, users can use the command line or the Homebrew package manager by typing brew install git.
After installation, it is extremely important to complete the initial configuration by entering your name and email. This data will be used to sign your commits, and without it, many remote repositories may reject push requests. Open a terminal or command line and enter the following commands, replacing the data with your own:
git config --global user.name"Your Name"
git config --global user.email"name@example.com"
Verifying the correct installation is carried out with a simple command git --version. If you receive a version number in response, it means the system is ready for use. Otherwise, you may need to restart your computer or manually add the path to the Git binaries to your operating system's PATH variable.
โ ๏ธ Warning: If you are using a corporate computer, your rights to install system software may be limited. In this case, contact your system administrator or use the portable version of Git if the security policy allows this.
Activating the Git plugin in Android Studio
Modern versions of Android Studio, based on the IntelliJ IDEA platform, already contain built-in support for Git. However, in some cases, the plugin may be disabled or not work correctly after updating the IDE. To make sure that the module is active, you need to go to the settings menu. On Windows and Linux, this is done via File โ Settings, and on macOS via Android Studio โ Preferences.
In the window that opens, find the section Plugins and enter "Git" in the search bar. Make sure the plugin called "Git Integration" or simply "Git" has the checkbox active. If it is disabled, enable it and click the Apply button. After this, the IDE will definitely require a restart to apply the changes.
You can also check for updates for the plugin in this section. JetBrains developers are constantly improving the functionality of working with branches, resolving merge conflicts, and visualizing history. Using the current version of the plugin guarantees compatibility with new functions of remote code hosting.
Setting the path to the executable file
The most critical step is telling Android Studio the exact location of the Git executable. Even if Git is installed on the system, the IDE may look for it in a non-standard location. To configure, go to the Version Control โ Git section in the settings menu. The field Path to Git executable must contain the correct path.
Usually Android Studio automatically finds the path, but if you see a red indicator or an error message, the path must be entered manually. For Windows, the standard path often looks like C:\app Files\Git\bin\git.exe. On macOS, the path may be /usr/bin/git or /opt/homebrew/bin/git depending on the installation method.
After specifying the path, click the Testbutton. If the configuration is correct, you will see the Git version number in the dialog box that appears. This means that the development environment successfully interacts with the installed version control system.
Below is a table with typical paths for various operating systems, which will help you quickly navigate:
| Operating system | Standard installation path | Alternate path (Homebrew/Custom) |
|---|---|---|
| Windows | C:\app Files\Git\bin\git.exe | C:\Git\bin\git.exe |
| macOS (System) | /usr/bin/git | - |
| macOS (Homebrew Intel) | - | /usr/local/bin/git |
| macOS (Homebrew ARM) | - | /opt/homebrew/bin/git |
| Linux (Ubuntu/Debian) | /usr/bin/git | /snap/bin/git |
If you use WSL (Windows Subsystem for Linux), to work with Git inside Android Studio on Windows, it is better to use native Windows Git, rather than the path to the binary inside WSL, to avoid problems with file system compatibility.
Creating a project and initializing the repository
After successfully setting up the paths, you can start creating a new project. When you launch the New Project wizard, Android Studio will prompt you to select a template, for example Empty Activity. At one of the final steps of the wizard, you will see a field Version control. Make sure the value is selected there Git.
If you forgot to select this option when creating, don't worry. You can initialize the repository at any time. To do this, select VCS โ Enable Version Control Integration (or Git โ Enable Version Control in new versions) in the top menu. Select Git from the list and the project's root folder will become tracked.
After initialization, all project files will be colored red, which means they are in the "Unversioned" status. This is a signal that Git sees the files, but has not yet started tracking their changes. To get started, you need to add files to the staging area index.
โ๏ธ Initial project setup
You can use the context menu to add all project files to the first commit. Right-click on the project root folder, select Git โ Add. The files will turn green, indicating they are ready to be committed. Now you can create your first saved history point.
Working with remote repositories
Storing code locally is useful, but for backup and team work you need a remote server such as GitHub, GitLab or Bitbucket. In Android Studio, this is implemented through the menu Git โ Manage Remotes. Here you can add the URL of your remote repository.
To add a remote repository, click plus, enter a name (usually origin) and URL. The URL can be copied from your repository page on your hosting site. After adding, the operation becomes available Git โ Push (or the key combination Ctrl+Shift+K / Cmd+Shift+K).
When you push for the first time, the IDE will request authorization. Modern versions of Android Studio support OAuth, allowing you to log in through a browser. This is more secure than using a login and password, especially if two-factor authentication is enabled on your account.
โ ๏ธ Attention: Menu interfaces and authorization methods may change with the release of new versions of Android Studio. If the standard login does not work, check the Token Access settings on the GitHub/GitLab website and create a Personal Access Token with rights to the repositories.
If you are cloning a finished project, use the option Get from VCS on the start screen. Paste the repository URL, select a local folder, and Android Studio itself will download the code, set up the paths and open the finished project.
What to do if there is a merge conflict?
A conflict occurs when two developers changed the same line of code. Android Studio will offer a Merge Tool, where you can visually choose which version of the code to keep: yours (Yours), theirs (Theirs), or merge manually.
Solving common problems and errors
During the process, you may encounter a situation where Git stops responding or the IDE gives indexing errors. This is often solved by a simple operation Git โ Repair or clearing the IDE cache through the menu File โ Invalidate Caches. It is also useful to check the output console (View โ Tool Windows โ Git), where detailed operation logs are displayed.
Another common problem is files being ignored. The file .gitignore in the project root determines which files do not need to be saved in the repository (for example, folder .idea, files build, local configs). Make sure this file is created and contains standard exceptions for Android projects.
If you changed the folder structure or moved the Git executable, be sure to update the path in the Version Control settings. Ignoring this step will cause all Git commands inside the IDE to stop executing, although everything will work in the terminal.
Regularly committing small changes and frequent pushes to a remote repository is the best strategy for protecting against data loss and complex conflicts when working together.
How to rollback the last commit in Android Studio?
To rollback the last commit, go to the Git Log window (Alt+9), find the commit, right-click and select "Reset Current Branch to Here". Be careful: this action will change the commit history.
Is it possible to work with multiple Git accounts?
Yes, Android Studio allows you to set up different accounts. When pushing to different repositories, the IDE may ask you to select an account or use saved credentials for a specific domain.
Where is the .gitignore file located in the project?
The .gitignore file is located in the root folder of the project. If you don't see it, turn on show hidden files in Explorer or switch the project view in Android Studio to "Project Files" mode.
Why doesn't Git see changes to files?
Make sure that the files are not added to .gitignore and that they are inside the root folder of the repository. Also check if the file is in "Assume Unchanged" mode.