top of page

Android Project to GitHub




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.


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.


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:

  1. Go to File > Settings

  2. Expand the section called "Version Control"

  3. Click the subsection called "Git"

In the window off to the right, you should see something similar to the following image.

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

  1. VCS (top toolbar) > Enable Version Control Integration

  2. Select "Git" in the popup window

  3. 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.

Once you're in the Project view

  1. Right-click on the folder with your applications name

  2. Go to Git > Add

  3. Again, Right-click on the folder with your applications name

  4. 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.



Pushing Project to GitHub

Once you have committed your files, it's time to push them out onto GitHub. To do this

  1. Select "Git" in the top toolbar

  2. Click "Push"

After you click the "Push" button, you should see the following window.


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.


After you click the "OK" button, assuming you're not already signed into your account, you will be prompted to log into GitHub.


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.


To generate this token, you must log in on GitHub. Once logged in, go to your settings and look for the Developer Settings section.


Once in the Developer's Section, click

  1. Personal access tokens

  2. Tokens (classic)

  3. Generate new token

  4. Generate new token (classic)


The following window will then appear.

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.

  1. repo (all)

  2. read:org

  3. 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.


24 views0 comments

Recent Posts

See All
bottom of page