, , ,

How to use GitHub with Android Studio

This article provides a basic overview of how to use GitHub with Android Studio. If you’re looking for more in-depth training, check out my ebook How to Use GitHub with Android Studio: A complete step-by-step guide to mastering the technology.

Click here to download an easy-to-follow PDF version of this post

Video Demonstration

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 Windows 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

And that’s it! I hope you found this post helpful? Let me know in the comments below.

Cheers,
Mark

Still having trouble? Check out Troubleshooting Common Problems in GitHub + Android Studio

 

 
Example anchor text

93 Responses

  1. Thank you for sharing this, it really helped me!

    1. Great, I’m glad you found it useful. How are you finding working with Android Studio so far?

  2. 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?

    1. Hi amd. Did you try to close Android Studio and re-open? This comment is a bit old so did you figure the solution already? If not, let me know.

  3. I’m trying to do this with my own project and it keeps giving me “Push rejected: master: rejected”. Any idea why?

    1. How did you fix this? I cant seem to get around this issue, even after restarting and setting up everything from scratch!

      1. Having the same issue with push rejection and not sure how to proceed. Any suggestions? Thanks.

  4. Nicely done. I had serious issues with rejections when I was trying from my home but 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?

    1. Glad it helped you. Not sure regarding the layout, can you send a screenshot to my email: mark (at) winterbottom.me…

  5. Very good tutorial with screenshots, I was stuck on “Nothing to push” message while pushing to github, you advice to Check the box Push current branch to alternative branch before pushing helped me a lot.

    Thanks again.

  6. Great article. I have a query, I wonder if you are aware of the answer to this. In the Android Studio “Commit Changes” option image in this blog the author field is empty, clicking on the dropdown shows my name and I select it every commit. Is there a way to set my name as default so that it automatically fills in when I goto VCS -> Commit Changes?

  7. that was awesome …point of correction not internet explorer its window explorer.Great job again and again now about to google on how to check out through git hub

    1. Thanks man, I’ve fixed it now 🙂 (No one want’s to use Internet Explorer for anything haha)

  8. Thank you. That was a perfect set of instructions and job done easy.

  9. Android Studio keeps on saying “Push to origin/master Rejected” I have no idea why and I have to submit some Android code soon.. to a tutorial.. please help

  10. Hi,

    Why I don’t have that option in my Android Studio?

    “the check box Push current branch to alternative branch”

    Thank you.

    1. Thank you so mach it’l very useful. i have one doubt how to create new branch and update project in my new branch via android studio.

  11. I got error when I push
    Failed with error: fatal: unable to access ‘https://github.com/Harin-Kaklotar/MyProject.git/’: Failed to connect to 127.0.0.1 port 8087: Connection refused

    1. Hi Harin. That is strange. It looks like github.com is resolving to 127.0.0.1 for you. In command prompt can you try and ping github.com and see what IP address it resolves?

  12. Hi

    I tried the steps you mentioned above and they were really helpful. I am facing a problem with Github 2 factor authentication, which does not allow me to login through android studio. Any idea how to resolve this ?

    Thanks

    1. Hi Shilpa. Great question. I just enabled Two Factor auth to test this myself. You are correct, Android Studio does not support GitHub Two Factor authentication. You can get round this pretty easily by using the GitHub private key authentication to clone your repository, and then open the repository in Android Studio.

      Let me know if this works for you or if you need more details.

  13. when I run my application by Android Virtual Devices (AVDs)
    I have problem

    there are Error message ” this AVD’s Configuration is Missing a kernal File ”

    I am waiting the Replying from Your And thank you on your Subject

    1. Hi Omar. That sounds like a problem with your Android Studio or Android SDK installation.

      I would need more details to figure out exactly what the issue is. My suggestion would be to re-install Android Studio and the Android SDK completely.

  14. Hello Mark,
    Thanks for the post. I have been able to create the GitHub repository for the project present in the Andriod studio located in my local machine. Your blog is wonderful. I have one query into it. I would be requiring the outputs folder content to be pushed into the GitHub as well, so can you let me know how to do it, as when I push the code currently, the output folder is not going into the Github.

    1. Hi Sayom, thanks for the comment and kind words about my blog. Did you try going to ‘VCS > Git > Add’ and ensuring the ‘output’ folder is added? If it doesn’t work, open your .gitignore folder and check that ‘outputs’ isn’t added to .gitignore.

  15. It was really helpful,That was a perfect set of instructions and job done easy.
    Thank you

  16. After following all your steps Push commits shows that ‘master -> Empty repository’. Will you help in this, i am using Android Studio 1.5.1

    1. Hi Nandha, are you still having this issue? Sounds like the files are not added before you commit?

    1. I had to rename branch from master to master2 and it worked

  17. Nice! Works with AndroidStudio 2.0 as well!!
    Only differenc is if you want to commit to different branch, leave the checkmark emty. It is has the oposit meaning in android 2.0.

    Thank You! I have no experience with eather Android studio or Git started googleing and found your tutorial fiirst thing probably saved me a couple of DAYS!! 😀 😀

    1. Hi Patrik, happy that you found it useful! Thanks for reading.

  18. Thank you so much! It works.
    The only problem is that my Github account has 2-step verification, so I encountered some trouble, fortunately I solved it.

  19. whenever i am writing in the shell program it says fatal:not a git repository

    1. Hi Sam, it sounds like the git repository hasn’t been initialized? Did you click “Create Git Repository”?

  20. Nice video! is there a follow-up to it? maybe something explaining how a different user then checks out the repository?

    1. Hi David, actually we are working on a follow up right now 🙂

  21. Thank you sir , it’s really helpful tutorial sir.

  22. That was awesome …point of correction not internet explorer its window explorer.Great job again and again now about to google on how to check out through git hub.It is useful information that i need this..
    Thanks for sharing this information to all……

  23. oh my god ,such a good tutorial,though I have config more than you mentioned but anyway it worked ,thank u so much ,sir

  24. thats not the default, its where ever you were last, so i add drawable. change the instructions to ensure pointing to the right place

  25. Thanks a lot mark, a great direction for the newbi user of android studio who want to switch from eclipse.

    Thanks once again

  26. Seemed to be working fine but on the final step (pushing the files) I get an error message that says:

    Push failed: Failed with error: fatal: repository ‘https://github.com/silverben10/henrysmith.git/’ not found

    Please would you be able to help?

    1. Hi Ben, thanks for the comment. Can you try removing the trailing slash from the end?

  27. […] also decided to take a minute and figure out the right way to upload projects from Android Studio to GitHub. I want that to develop into a habit that I don’t have to think about. I think I’ve […]

  28. Thanks for the post. It was great. (Cheers)

    1. Sounds like maybe you need to initialise the project as a Git repo within the VCS menu at the top of Android Studio?

  29. Man ,can you tell me how to use git from two android studio to work on a same project and make changes from two systems.what all steps are there for doing that.

    1. Hi Pritz, assuming you already have the project on one computer, you would push to GitHub using the instructions on this post, and then on the second computer you would clone it. Then when you make a change on either one, you push the changes and then on the other machine you pull the changes. Does that make sense?

  30. Yeah man ,i am convinced with your answer but i want more deep information about this thing…
    As we are working on the firebase app so.. in order to fully access the codes privilege from the 2 devices(me and my team partner).. what are the things we need to set up..

  31. pushing ins’t a success cause i get the error ” Failed with error: fatal: unable to access ‘https://github.com/darkfly0010/Darknote.git/’: Unknown SSL protocol error in connection to github.com:443 ” .please help

  32. Do you know how how to get ssh key to gain access in github

  33. Great work marks. Thanks for this worthy information.

Leave a Reply

Your email address will not be published. Required fields are marked *

Download PDF
How to use GitHub with Android Studio PDF
We guarantee 100% privacy. Your information will not be shared.
%d bloggers like this: