How to add an Android Studio project to GitHub

AndroidGitAndroid Studio

Android Problem Overview


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?

Android Solutions


Solution 1 - Android

  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.

Solution 2 - Android

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

Solution 3 - Android

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.

Solution 4 - Android

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTony BabyView Question on Stackoverflow
Solution 1 - AndroidTony BabyView Answer on Stackoverflow
Solution 2 - AndroidOleg KhalidovView Answer on Stackoverflow
Solution 3 - AndroidRohit PatilView Answer on Stackoverflow
Solution 4 - AndroidPrashant Kumar SharmaView Answer on Stackoverflow