191

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?

1

4 Answers 4

456
  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.
9
  • 6
    how do i commit after i make a change ? Commented Jul 30, 2016 at 4:52
  • 33
    Go to VCS -> Git -> Commit file . Then type a commit message and click on commit button.
    – Tony Baby
    Commented Jul 30, 2016 at 17:50
  • 1
    youtube.com/watch?v=ZnS7fMPfbI8 Commented Dec 1, 2017 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 stackoverflow.com/questions/11928561/where-is-git-exe-located ...I hope it helps too.
    – Nikhil G
    Commented Jan 11, 2018 at 1:52
  • 1
    Not working, must log in with token which has certain rights.
    – Robbie
    Commented May 7, 2021 at 13:10
133

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
6
  • 5
    also config email and password if pushing code for the first time. stackoverflow.com/a/33024593/3496570 Commented Jul 10, 2017 at 6:25
  • 5
    please add a .gitignore file
    – Yashas
    Commented Jan 20, 2019 at 15:23
  • 1
    in case of error, use -f (force push) git push -f origin master. Warning: force push might remove the remote history.
    – Shachi
    Commented May 7, 2019 at 9:22
  • 1
    This is a great option if you already created the project on GitHub, otherwise I find Tony's answer easier. I guess it also depends if you like using the terminal or not.
    – jonasxd360
    Commented Jul 15, 2019 at 18:22
  • is this in AS terminal?
    – MwBakker
    Commented Dec 26, 2020 at 13: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.

1
  • "Can't create user repository Can't parse GitHub response"
    – MwBakker
    Commented Dec 26, 2020 at 13:48
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.

3
  • 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
    Commented Mar 24, 2018 at 0: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
    Commented Mar 24, 2018 at 0:36
  • 1
    Best answer. The others don't work with the New Android Studio
    – live-love
    Commented Feb 26, 2021 at 19:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.