How to use GitHub with Android Studio

How to use GitHub with Android Studio | London App Developer

UPDATE: This is an old tutorial written for Android Studio Beta. Since then there have been some updates and (although the below will still work) you may find it quicker to follow my updated tutorial How to use GitHub with Android Studio 1.x.

This article will explain how to use GitHub with Android Studio.

Firstly, let’s login to github.com and create a new repository. From the top right corner of the screen, click the + sign and select New repository.

技术分享 GitHub “New repository” option

Now complete the form to create a new repository called testproject. Leave the Initialize this repository with a README unticked.

技术分享 GitHub create new repository form

Next, open Android Studio and create a new project. Call your new application TestProject. Click Next to continue.

技术分享 Android Studio new project window

Leave the next page as default and click Next.

技术分享 Android Studio “Select the form factors your app will run on” screen

On the Add an activity to Mobile screen select Blank Activity and click Next.

技术分享 Android Studio “Add an activity to Mobile” screen

In the next screen, leave the default activity name of MyActivity and click Finish.

技术分享 Android Studio “New file options” screen

Your new project will open in Android Studio. On the top menu, select VCS > Import into Version Control > Create Git Repository.

技术分享 Android Studio “Create Git Repository” option.

On the next screen, leave it all as default and click OK.

技术分享 Android Studio “Select directory for git init” screen

Now use Internet Explorer and navigate to the root of your projects folder. Right click and select Git Bash (If you do not see this option, then first install Git for Windows).

When the Git bash screen appears, type:

git remote add origin https://github.com/[username]/[project_name].git

An example of a Git repository URL is: https://github.com/markwint/testproject.git

技术分享 Entering command into Git Bash

Then press enter. The GitHub remote will be added to your Git repository.

Next, jump back into Android Studio, right click your projects root directory and select Git > Add. This will add all your project files to your Git repository.

技术分享 Android Studio “Git > Add” option

It will seem like nothing has happened, but trust me, the project files are added.

Now right click the project name again and this time select Git > Commit Directory.

技术分享 Android Studio “Commit Directory” option

In the next screen, type a Commit Message and select Commit.

技术分享 Android Studio “Commit Changes” option

If a Code Analysis warning appears, click Commit. (Unless it’s a real project, in which case review and fix the issue before committing!)

技术分享 Android Studio “Code Analysis” warning

Now, right click the project name, select Git > Repository > Push.

技术分享 Android Studio “Git Push” option

Check the box Push current branch to alternative branch and leave the branch name as master. Then select push.

技术分享 Android Studio “Git Push” prompt

Now enter your GitHub Login (email address) and Password. Then click OK.

技术分享 Android Studio GitHub Remote Login

If it’s all good, you will see this message.

技术分享 Android Studio Successful Git Push

Now your code is pushed to your GitHub repository. Don’t believe me? Logon and check for yourself.

技术分享 GitHub repository pushed from Android Studio

Hope that was helpful.

 

14 Comments

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。