[Android] How to use github with android studio

来源:互联网 发布:js输入框输入触发事件 编辑:程序博客网 时间:2024/05/18 03:04

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:

Setting up VCS for the current project

Step 1: Configuring the VCS

From the Welcome screen-> Configure -> Project Defaults-> Settings -> Version ControlIn the Version Control Menu select Github

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

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

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

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.

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

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.

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”:

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

commit changes
write your Commit MessageCommit (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.

0 0