How to add Android-Project to GitHub [duplicate]
Asked Answered
R

3

17

I'm using Android Studio to code my apps. Now I want to work on 2 PC's and thought about using a Cloud-Service. I decided to use GitHub, but I can't find a way to synchronize my GitHub account with my Android Studio project... Can anyone explain this to me ?

Retard answered 17/11, 2014 at 19:1 Comment(0)
S
41

Best way to do this is probably through the good ol' command line. First, make sure you have git installed and in your path. You can get instructions from here.

Next, go to GitHub and create a new repository with a title and such. Instructions on that here. Don't worry about creating your first commit, we're going to do that on your local machine.

Now for the fun part.

Copy the repo link of your choice (I prefer ssh, but it depends on how far you went with the set up part) and head to the terminal.

cd ~/project-path-here
git init
git add .
git commit -am "initial commit"
git remote add origin <your link>
git push -u origin master

If all has gone well, you can reload the github page and see your new push.

On your other computer, you'll be able to clone down the repo you created.

cd ~/project-path-here
git clone <your link>

You can then use git pull and git push to retrieve and send changes to the server.

You can also look into Github's desktop application if you're on Windows or Mac for a simpler time, but I find these lack some more advanced features of git.

EDIT: To register your new git repo with Android Studio, Intellij, RubyMine, etc., go to the project settings (File->Settings), search for version control, and specify that your project is using git for version control. Here for more information on that. Once that is enabled, the VCS drop down will have more features. The ones to look at are Commit Changes (git commit and push) and Update Project (git pull).

Sacculate answered 17/11, 2014 at 19:24 Comment(4)
Thanky you for this long and good answer! I know now how to push and pull via terminal. Now I want to push the project into my GitHub via Android Studio, how can I do this ?Retard
I updated my answer with the Android Studio stuff, but I would definitely recommend using the command line over Android Studio.Sacculate
Now it works ! ;) Thank you! Android Studio just opens GitHub and there I can sync the files (with the GUI from GitHub)Retard
I've been trying to do push to GitHub via Android Studio and it kept saying it was already on there, but this worked for me!Ingressive
R
4

Under the VCS tab in your Studio, there's on option to publish the project to Github. Will ask for your credentials, then you're good to go to push your code.

Recompense answered 17/11, 2014 at 19:3 Comment(3)
I tried every option under the VCS tab, but it didn't work for me ... For example: VCS/Import into Version Controle/Share Project on GitHub just opens GitHub on my desktop and I can't click anythingRetard
a. Do you have a Github account and b. did you already create a local repository? If not, do it. Also c. do you have git installed?Recompense
a. yes b. yes I have created oneRetard
F
2

Just getting into Android app dev and I thought I might mention here that I think that we should gitignore the build folder. It's huge and it doesn't need to be repo'd [Edit] I'm referring to the app/build folder. And hey I see it's not included in the Android Studio .gitignore

Feature answered 18/4, 2016 at 17:39 Comment(2)
.gradle /local.properties .DS_Store /build .navigation .idea *.iml *.log *.hprof This is the gitignore I use, after one year of android developmentRetard
I use gitignore.io for most of my gitignore needs. I haven't developed in intellij or with android for a while, so I'm not sure if it's up to date.Sacculate

© 2022 - 2024 — McMap. All rights reserved.