188

I have a project in Android Studio. I want to add that project to a GitHub repository using android studio. How can I do that?

Tony Baby
  • 7,176
  • 6
  • 18
  • 22
  • 7
    Duplicate of [this](http://stackoverflow.com/questions/23330825/how-do-i-add-my-project-from-android-studio-to-my-github-page) and [this](http://stackoverflow.com/questions/16644946/how-do-you-sync-projects-to-github-with-android-studio)? – roarster May 07 '16 at 21:12

4 Answers4

453
  1. Sign up and create a GitHub account in www.github.com.
  2. Download git from https://git-scm.com/downloads and install it in your system.
  3. Open the project in android studio and go to File -> Settings -> Version Control -> Git.
  4. Click on test button to test "path to Git executables". If successful message is shown everything is ok, else navigate to git.exe from where you installed git and test again.
  5. Go to File -> Settings -> Version Control -> GitHub. Enter your email and password used to create GitHub account and click on OK button.
  6. Then go to VCS -> Import into Version Control -> Share Project on GitHub. Enter Repository name, Description and click Share button.
  7. In the next window check all files inorder to add files for initial commit and click OK.
  8. Now the project will be uploaded to the GitHub repository and when uploading is finished we will get a message in android studio showing "Successfully shared project on GitHub". Click on the link provided in that message to go to GitHub repository.
Tony Baby
  • 7,176
  • 6
  • 18
  • 22
  • 6
    how do i commit after i make a change ? – Sagar Nayak Jul 30 '16 at 04:52
  • 33
    Go to **VCS** -> **Git** -> **Commit file** . Then type a commit message and click on **commit button**. – Tony Baby Jul 30 '16 at 17:50
  • 1
    https://www.youtube.com/watch?v=ZnS7fMPfbI8 – Piash Sarker Dec 01 '17 at 21:06
  • On step 3rd, i would like add something. When you install git on windows, it doesn't show you its exe file easily. So, you would need to do a little hard work at this point to search the path of git exe. Here I found this post useful in order to search this path, click https://stackoverflow.com/questions/11928561/where-is-git-exe-located ...I hope it helps too. – Nikhil G Jan 11 '18 at 01:52
  • Is it safe to public android project on GitHub? because the JSON file is there and anyone can see the id. What if someone copies my application? I made it public to showcase my work when I was applying for an internship. – Vijay Nov 01 '20 at 10:58
  • Logging into Github per AS may for some only work per token (no idea why) https://stackoverflow.com/a/64957496/4895256 – MwBakker Dec 26 '20 at 13:26
  • Did all the work just to get a "Can't create user repository Can't parse GitHub response" I think AS is not optimalized for github – MwBakker Dec 26 '20 at 13:38
  • 1
    Not working, must log in with token which has certain rights. – Robbie May 07 '21 at 13:10
  • this answer is outdated whether edit the right answer or mention it, there's no login password in github section, must have changed with recent versions – Alireza Jamali Mar 12 '23 at 18:44
130

You need to create the project on GitHub first. After that go to the project directory and run in terminal:

git init
git remote add origin https://github.com/xxx/yyy.git
git add .
git commit -m "first commit"
git push -u origin master
Oleg Khalidov
  • 5,108
  • 1
  • 28
  • 29
84

If you are using the latest version of Android studio, then you don't need to install additional software for Git other than GIT itself - https://git-scm.com/downloads

Steps

  1. Create an account on Github - https://github.com/join
  2. Install Git
  3. Open your working project in Android studio
  4. GoTo - File -> Settings -> Version Controll -> GitHub
  5. Enter Login and Password which you have created just on Git Account and click on test
  6. Once all credentials are true - it shows Success message Or Invalid Cred.
  7. Now click on VCS in android studio menu bar
  8. Select Import into Version Control -> Share Project on GitHub
  9. The popup dialog that will occur contains all your files with check mark, do ok or commit all
  10. At next time whenever you want to push your project just click on VCS - > Commit Changes -> Commit and Push.

That's it. You can find your project on your GitHub now.

ikmazameti
  • 131
  • 3
  • 12
Rohit Patil
  • 1,615
  • 12
  • 9
69

First of all, create a Github account and project in Github. Go to the root folder and follow steps.

The most important thing we forgot here is ignoring the file. Every time we run Gradle or build it creates new files that are changeable from build to build and pc to pc. We do not want all the files from Android Studio to be added to Git. Files like generated code, binary files (executables) should not be added to Git (version control). So please use .gitignore file while uploading projects to Github. It also reduces the size of the project uploaded to the server.

  1. Go to root folder.
  2. git init
  3. Create .gitignore txt file in root folder. Place these content in the file. (this step not required if the file is auto-generated)

    *.iml .gradle /local.properties /.idea/workspace.xml /.idea/libraries .idea .DS_Store /build /captures .externalNativeBuild

  4. git add .
  5. git remote add origin https://github.com/username/project.git
  6. git commit - m "My First Commit"
  7. git push -u origin master

Note : As per suggestion from different developers, they always suggest to use git from the command line. It is up to you.

Prashant Kumar Sharma
  • 1,120
  • 1
  • 11
  • 21
  • 1
    Correct. This is the only answer that covered the case of the files that have to be ignored. Otherwise, conflicts may appear across developers, because if you commit *all* the files that will include local paths and variables (like the local.properties file) that are not the same on different Dev's computers. +1 – DarkCygnus Mar 24 '18 at 00:23
  • 7
    As a side comment, maybe it is something that the new Android (3.0) does, but seems that it automatically creates the .gitignore file when you create a new Android Project. Great feature IMO for those people that tend to forget those details (like me :) – DarkCygnus Mar 24 '18 at 00:36
  • 1
    Best answer. The others don't work with the New Android Studio – live-love Feb 26 '21 at 19:38