Update:this is a old tutorial written for Android Studio Beta. Since Then there has been some updates and (although the below would still work), you could find it quicker to follow my upda Ted Tutorial How to the use of GitHub with Android Studio 1.x.
This article would 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 screens, 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 would run on" screen
On the Add a 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 would 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 screens, 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 don't 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 is added to your Git repository.
Next, jump to Android Studio, right click your projects root directory and select Git > Add. This would add all your project files to your Git repository.
Android Studio "Git > Add" option
It would seem like nothing had happened, but trust me, the project files is added.
Now right click on the project name again and this time select Git > Commit Directory.
Android Studio "Commit Directory" option
In the next screen, type a commits 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'll see the this message.
Android Studio Successful Git Push
Now your code was pushed to your GitHub repository. Don ' t believe me? Logon and check for yourself.
GitHub repository pushed from Android Studio
Hope that was helpful.
Comments
- Messerli Vinzenz says: September at 8:22 am
Thank sharing This, it really helped me!
Reply
- Prashant Pandey says: October at 5:55 pm
thank Sir
Reply
- Noman says: October at 10:06 am
Thank you. It works
Reply
- AMD says: November at 11:34 am
I may have entered a wrong password, it says "Push rejected". The Enter password popup is not showing again. How can I re-enter my password?
Reply
- Wrolf says: December 7 at 5:47 pm
Thank. Just what I needed.
Reply
- Piotrek says: December at 8:36 am
Excellent Article–thank you very much!
Reply
- Zeeshan says: January 3 at 12:20 pm
Thank you much. It works!
Reply
- Jess says: January 5 at 1:04 am
I ' m trying to does this with my own project and it keeps giving me "Push rejected:master:rejected". Any idea why?
Reply
- luditetechnologies says: January at 2:15 pm
Nicely done. I had serious issues with rejections when I am trying from my home and I tried this tutorial again from my office with a Different project and it worked flawlessly.
I have one Question:my final layout (the project tree structure, I mean) looks slightly different from your screenshot At the end. Does that matter at all?
Reply