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 ?

Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
Oliver
  • 503
  • 1
  • 3
  • 13

3 Answers3

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).

afontaine
  • 1,059
  • 9
  • 9
  • 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 ? – Oliver Nov 17 '14 at 21:44
  • I updated my answer with the Android Studio stuff, but I would definitely recommend using the command line over Android Studio. – afontaine Nov 17 '14 at 22:33
  • Now it works ! ;) Thank you! Android Studio just opens GitHub and there I can sync the files (with the GUI from GitHub) – Oliver Nov 19 '14 at 13:32
  • 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! – mur7ay Apr 08 '16 at 22:29
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.

fweigl
  • 21,278
  • 20
  • 114
  • 205
  • 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 anything – Oliver Nov 17 '14 at 19:08
  • 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? – fweigl Nov 17 '14 at 19:10
  • a. yes b. yes I have created one – Oliver Nov 17 '14 at 19:12
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

peterb
  • 891
  • 8
  • 7
  • .gradle /local.properties .DS_Store /build .navigation .idea *.iml *.log *.hprof This is the gitignore I use, after one year of android development – Oliver Apr 19 '16 at 18:13
  • 1
    I use http://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. – afontaine Jun 20 '16 at 21:11