Connect Android Studio Project with GitHub

So, you want to start a new Android project. I’m happy to hear that.

But first, a strategic consideration of how you want to manage the project as such.

If we create a new project in Android Studio, we can determine where the project will be saved. I assume that most have chosen an appropriate place on the hard disk.
If you choose this strategy, you should at least make a backup of the project directory regularly in the event of a major error to have a flawless base on which to fall back.

A more professional approach is to link the project with a “Version Control System” (VCS).

The advantages here are that any change will be documented and there is a “fall back” for your use. So you can return at a greater mistake on an earlier version of the project.
Integrated into Android Studio are the VCS Git, Mercurial, and Subversion.
This means that projects after a slight configuration with the GitHub servers can be connected. Both Github as well Bitbucket build on the VCS Git. But if you want to work with Bitbucket, a corresponding plug-in must be installed before.

Infos about this Bitbucket integration can be found here:
http://plugins.jetbrains.com/plugin/6207?pr=androidstudio
https://bitbucket.org/atlassian/jetbrains-bitbucket-connector/

For this tutorial, the project will be connected to Github.

The meaning of this post is to give you a quick start to get you up and running.

Using Version Control (VCS)

Android Studio can work with the following VCS:
Git, GitHub, Mercurial, and Subversion.
To use one of the systems, you must have the appropriate program that is used by the VCS installed on the computer. For Git, GitHub and Bitbucket this would be the “git”, for Mercurial “hg” and subversion “svn”.

If you’re not familiar with Github, please visit Github’s Guide.

For the following steps, I will use the “Hello World” Project from the tutorial:

Your very first app with Android Studio – starting from scratch

 

Setting up VCS for the current project

Step 1: Configuring the VCS

From the Welcome screen

-> Configure -> Project Defaults

-> Settings -> Version Control

In the Version Control Menu select Github

Screenshot from 2015-04-28 15:58:35

Setting up GitHub

To connect the project with GitHub, you have to use a previously opened GitHub account otherwise click on the GitHub “Sign up” button.

To make sure that the connection is working, press the Test button and wait for the success message.

Close the Window to get back to the Welcome Screen and open the project you want to connect or start a new project.

I open the Hello World project from earlier which was automatically named “My Application”.

Screenshot from 2015-04-28 16:04:33

Step 2: Enable VCS in the current project

To activate the current Project for cooperation with a VCS, you choose from the menu bar “VCS” and then “Enable Project for Version Control Integration”.

Only now, the menu offers all VCS related resources such as, “share project on GitHub”.

Go ahead and choose from the VCS menu

-> Import into Version control

-> Share Project on Github

Screenshot from 2015-04-28 16:09:56

The repository name had to be changed from “My Application” into “MyApplication”.

Screenshot from 2015-04-28 16:10:14

All the current files from this project are going to be uploaded to Github.

If you go to the bottom of your screen, you can now choose from the toolbar “Version Control” and control/ manage your project with Github.

Screenshot from 2015-04-28 16:19:39

 

So far, we did all the work from our Android Studio IDE. Let’s go to GitHub and take a look at the repository:

https://github.com/greendogs/MyApplication

When I was on the GitHub repository, I added a README file to the project.

How to synchronize changes from the GitHub repository to the local repository (Android Studio Project)?

Go to the VCS menu and choose “Update Project ..”

Confirm the pop-up menu

Screenshot from 2015-04-29 07:18:49

 

Depending on your Internet connection and the size of the file you wish to synchronize, it takes some seconds to some minutes.

After the synchronization has finished, you can see it in the VCS notification window.

Screenshot from 2015-04-29 07:19:58

 

Now, I’m going to make a change on my project in Android Studio. To keep it simple, I only changed the background color from the activity_main.xml.

The changes have been recognized by the VCS and been documented. You can see the documentation of any change in the notification window on the bottom, under “Changes”:

Screenshot from 2015-04-29 07:36:59

To synchronize the local changes with the online GitHub repository, go to VCS and choose:

  • commit changes

Screenshot from 2015-04-29 07:38:46

 

  • write your Commit Message
  • Commit (commit and push)

The changes can be seen on the GitHub repository right away.

This is the End of the Quick Start Tutorial. Now, it’s your turn to explore all the VCS related features that are available in Android Studio.

PS:

You don’t have to setup a special local repository for this project. The local repository is your project location.

 

Good Luck!

See you next time.