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?
4 Answers
- Sign up and create a GitHub account in www.github.com.
- Download git from https://git-scm.com/downloads and install it in your system.
- Open the project in android studio and go to File -> Settings -> Version Control -> Git.
- 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.
- Go to File -> Settings -> Version Control -> GitHub. Enter your email and password used to create GitHub account and click on OK button.
- Then go to VCS -> Import into Version Control -> Share Project on GitHub. Enter Repository name, Description and click Share button.
- In the next window check all files inorder to add files for initial commit and click OK.
- 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.
-
6
-
33Go to VCS -> Git -> Commit file . Then type a commit message and click on commit button. Jul 30, 2016 at 17:50
-
1
-
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 GJan 11, 2018 at 1:52
-
1
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
-
4also config email and password if pushing code for the first time. stackoverflow.com/a/33024593/3496570 Jul 10, 2017 at 6:25
-
4
-
1in case of error, use -f (force push) git push -f origin master. Warning: force push might remove the remote history.– ShachiMay 7, 2019 at 9:22
-
1This 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. Jul 15, 2019 at 18:22
-
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
- Create an account on Github - https://github.com/join
- Install Git
- Open your working project in Android studio
- GoTo - File -> Settings -> Version Controll -> GitHub
- Enter Login and Password which you have created just on Git Account and click on test
- Once all credentials are true - it shows Success message Or Invalid Cred.
- Now click on VCS in android studio menu bar
- Select Import into Version Control -> Share Project on GitHub
- The popup dialog that will occur contains all your files with check mark, do ok or commit all
- 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.
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.
- Go to root folder.
git init
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
git add .
git remote add origin https://github.com/username/project.git
git commit - m "My First Commit"
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.
-
1Correct. 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 Mar 24, 2018 at 0:23
-
7As 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 :) Mar 24, 2018 at 0:36
-
1