Getting Started
The first thing you want to do is check if you have Git installed on your computer. To do this, open a terminal and type the following command.
git --version
If the terminal outputs a version for git, you can skip to the next section. If, however, you received an error message which sounded similar to the following:
‘Git’ is not recognized as an internal or external command
Then you'll need to install Git onto your computer before moving further.
Installing Git
If you're unaware, Git is a commonly used version control system that tracks changes to a given set of files. To install this, make your way to the following webpage. You should see a section that looks similar to the next picture.
![](https://static.wixstatic.com/media/8258e5_f37a10be660a419ca50e6a7908d6442b~mv2.jpg/v1/fill/w_127,h_118,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/8258e5_f37a10be660a419ca50e6a7908d6442b~mv2.jpg)
IMPORTANT NOTE: Keep the default installation path! Android Studio can auto-detect the installation location of Git, which allows no further action on your part.
Installing on Windows
Based on the image above, click on the windows operating system link. You should see a page similar to the picture shown below.
![](https://static.wixstatic.com/media/8258e5_4c169a4b53a34f16805bf11fff155f3e~mv2.jpg/v1/fill/w_124,h_62,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/8258e5_4c169a4b53a34f16805bf11fff155f3e~mv2.jpg)
From here, choose one of the standalone installers. If you're unsure if you have a 32-bit or 64-bit operating system, open the terminal and type the following command.
systeminfo
Once the command has fetched all the system information, you're looking for the label that says System Type. If you have an x64 next to the label, download the 64-bit installer; otherwise, download the 32-bit installer. After the file finishes downloading, follow the instructions presented in the installation wizard. I kept everything as the default value (clicking next about a million times).
Installing on Linux
Type the following command into the terminal to install Git on Fedora or a distribution of Linux closely related.
sudo dnf install git-all
If you're on a Debian-based Linux distribution like Ubuntu, type the following command into the terminal.
sudo apt install git-all
Installing on macOS
If you have Xcode Command Line Tools installed, simply trying to see what version of Git is installed on your computer will prompt you to install it.
Once the installation is complete, open the terminal and type the following command.
git --version
This time, you should see a version in response to entering that command into the terminal.
Setting up Git in Android Studio
Now that Git is installed on your computer let's ensure that Android Studio can find the installation location. To check this:
Go to File > Settings
Expand the section called "Version Control"
Click the subsection called "Git"
In the window off to the right, you should see something similar to the following image.
![](https://static.wixstatic.com/media/8258e5_3e296381133d41a7b899c3999ee0a8b9~mv2.jpg/v1/fill/w_145,h_107,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/8258e5_3e296381133d41a7b899c3999ee0a8b9~mv2.jpg)
In the topmost section, you should see "Auto-detected: path to git.exe" in the "Path to Git executable" section. If you don't see this, click the folder icon and navigate to the location where you have "git.exe" installed. Once you have the location specified, click the "Test" button. If everything is working correctly, the version of Git you installed should appear in the window.
Setting up the Version Control System (VCS)
To enable version control in your Android Studio project, go to
VCS (top toolbar) > Enable Version Control Integration
Select "Git" in the popup window
Click the "OK" button
After doing this, your files should then turn red. Don't worry; this is normal. After this, change your project view from "Android" to "Project." The drop-down will be located towards the top left.
![](https://static.wixstatic.com/media/8258e5_e4bf631c5c5745cda226abc42cebdda4~mv2.jpg/v1/fill/w_105,h_112,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/8258e5_e4bf631c5c5745cda226abc42cebdda4~mv2.jpg)
Once you're in the Project view
Right-click on the folder with your applications name
Go to Git > Add
Again, Right-click on the folder with your applications name
Go to Git > Commit Directory
A new window like the one shown below will appear. Type in an initial commit message and click the "Commit" button.
![](https://static.wixstatic.com/media/8258e5_14bbb0d971624942a373a0a0d5684016~mv2.jpg/v1/fill/w_147,h_114,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/8258e5_14bbb0d971624942a373a0a0d5684016~mv2.jpg)
Pushing Project to GitHub
Once you have committed your files, it's time to push them out onto GitHub. To do this
Select "Git" in the top toolbar
Click "Push"
After you click the "Push" button, you should see the following window.
![](https://static.wixstatic.com/media/8258e5_37682a94d05d4e0ebf857fb6383ffacc~mv2.jpg/v1/fill/w_144,h_95,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/8258e5_37682a94d05d4e0ebf857fb6383ffacc~mv2.jpg)
We don't have a repository to which we can push the files. To set one, click the "Define remote" button and paste the URL to your repository in the popup window that appears.
![](https://static.wixstatic.com/media/8258e5_2b4a51f92c6448b28b1409576ca06741~mv2.jpg/v1/fill/w_82,h_39,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/8258e5_2b4a51f92c6448b28b1409576ca06741~mv2.jpg)
After you click the "OK" button, assuming you're not already signed into your account, you will be prompted to log into GitHub.
![](https://static.wixstatic.com/media/8258e5_94a84041f2a44c259499744531d4dfb3~mv2.jpg/v1/fill/w_109,h_36,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/8258e5_94a84041f2a44c259499744531d4dfb3~mv2.jpg)
Creating an Access Token
You can either log in via GitHub (the blue button) or use an access token. I always use the access token because I can set an expiration date on the token, preventing any further changes to my repository after the set date.
Click the "Use Token" button, and the following window will appear, asking you to enter your access token.
![](https://static.wixstatic.com/media/8258e5_71de7b5e1d56467cb59f41f9125e252b~mv2.jpg/v1/fill/w_114,h_49,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/8258e5_71de7b5e1d56467cb59f41f9125e252b~mv2.jpg)
To generate this token, you must log in on GitHub. Once logged in, go to your settings and look for the Developer Settings section.
![](https://static.wixstatic.com/media/8258e5_cbb17a22cdad404c801f3909105e8525~mv2.jpg/v1/fill/w_147,h_64,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/8258e5_cbb17a22cdad404c801f3909105e8525~mv2.jpg)
Once in the Developer's Section, click
Personal access tokens
Tokens (classic)
Generate new token
Generate new token (classic)
![](https://static.wixstatic.com/media/8258e5_d7fbc204ef5246ed82ca002823221328~mv2.jpg/v1/fill/w_147,h_40,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/8258e5_d7fbc204ef5246ed82ca002823221328~mv2.jpg)
The following window will then appear.
![](https://static.wixstatic.com/media/8258e5_a8e4f7c25d804b71ac99282a2dd6ecc7~mv2.jpg/v1/fill/w_147,h_60,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/8258e5_a8e4f7c25d804b71ac99282a2dd6ecc7~mv2.jpg)
In this window, you can make a note about the token and set an expiration date. In this section, you must select a few scopes for this token to allow you to add files to the repository. The required scopes are listed below.
repo (all)
read:org
gist
Once the required scopes are selected, click the green "Generate Token" button. Copy and paste it into the login window in Android Studio and click "Log In." After completing that, you should now be logged into your GitHub account. Finally, click the "Push" button to add the new files to your repository.