How to add Android-Project to GitHub

33.9k views Asked by At

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 ?

3

There are 3 answers

4
afontaine On BEST ANSWER

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

3
fweigl On

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.

2
peterb On

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