61

So I am new to Android development and Android Studio.

I used Android Studio to create an Android project, and each time I wanted to commit the code to GitHub, I switched over to the command line and committed/pushed the code from there.

However, I realize now that Android Studio has it's own features for connecting to GitHub. I'd like to use those features.

Since the project already exists, I prefer not to just create a new GitHub repository from Android Studio and delete the old one. I just want to connect the existing GitHub repository with the Android Studio project.

How can I sync these up?

4
  • 1
    Running into the same issue and just wondering if you ended up just making a new repo like you mentioned? Thanks! Commented Jan 14, 2016 at 23:02
  • 1
    Android studio was able to detect my VCS automatically. I'm not sure why it gave me trouble in the beginning. I mostly just use the command line now though anyway.
    – johncorser
    Commented Jan 14, 2016 at 23:09
  • 1
    Hi I am facing the same problem and would like to know what do you mean by "Android studio was able to detect my VCS automatically"? How can try again if it is not detecting it? Commented Jun 25, 2016 at 2:00
  • Here is the way I did it.
    – Suragch
    Commented Dec 22, 2016 at 13:19

7 Answers 7

28

Maybe it is a little bit late, but if it helps to someone here is what I do in command line:

cd <proyect folder>
git init
git remote add origin <link to repo>
git fetch origin
git checkout master

note: if there are commits on the repo it may require you to remove conflicting files

git add --all
git commit -m "<message>"
git push
1
  • Thanks, this is what I was looking for. If only I could find a way to do it in GUI in Android Studio.
    – NullByte08
    Commented Feb 1, 2020 at 14:53
17

Connecting existing Android Studio project to existing Github repository

If your local project is newer than the one on GitHub, then you can temporarily move it to another location, import the GitHub version into Android studio, delete these old files, and copy in the new files. Then push the changes back to GitHub. The directions to do all of this are here. This takes some command line work, but after it is set up, you can do any future commits right in Android Studio.

Committing and pushing to GitHub from Android Studio

After making a change, you can commit it by selecting the app folder in the Android view (or the main project folder in whatever view you are using). Then go to VCS > Git > Commit Directory....

enter image description here

Add a commit message and click Commit.

enter image description here

Then go to VCS > Git > Push to push your changes to GitHub.

enter image description here

That's it.

1
  • really helpful !! Commented Mar 22, 2018 at 6:12
9

I would view this thread if you want to create a new project.

How do you synchronise projects to GitHub with Android Studio?

If this doesn't help then I would just delete your current(local) project and import from github.

http://teamtreehouse.com/library/android-tools/git/pulling-down-github-projects-to-android-studio

I would recommend staying with command line. It is great practice. View link below for more information.

https://softwareengineering.stackexchange.com/questions/173297/why-learn-git-when-there-are-gui-apps-for-github

3
  • 1
    Really? Is git used from the command line rather than as an ide extension in industry? Also, the thread you refer to is for new repositories (mine already exist). Looks like I might have to just delete and import.
    – johncorser
    Commented Oct 13, 2014 at 19:10
  • It varies in the industry. Just depends on the team/company that you join. You gain a greater understand of git by using command line. Otherwise you are just clicking buttons =) Commented Oct 13, 2014 at 19:15
  • 1
    I have a firm grasp of git from the command line, and not a great grasp of the IntelliJ IDE, which I am likely to use if I seek out a job in industry working on Android apps or Java code.
    – johncorser
    Commented Oct 13, 2014 at 19:16
4

Update 2022

Make sure to have the Github account and VCS set. If you haven't done so check out the first few steps here.

Connect with your repository

  1. In the tab bar go to Git>Manage Remotes...
  2. Press the plus sign to add a new remote:
Name: yourCustomRemoteName (default: origin)
URL: https://github.com/yourName/yourRepository
  1. Done!
1
1

This may help but I find it easier to the use the Git Hub desktop software which can be found here for mac: mac.github.com and here for windows: windows.github.com.

Based on my use of the mac one.

1

I was having the same issue and was looking for a solution. The answers provided on this thread are useful as git goes, but didn't answer my question. After some tinkering around I found my own solution. I cloned the git repository that I wanted to merge my existing Android Studio Project with. I copied over the '.git' folder from the cloned repository to my main Project folder for Android studio. I staged files and committed them, and pushed them to the existing git repository. Doing so updated my git repository with my existing project. I didn't have to create a new Git repository.

Make note that you will have to set up your "remotes" as you would have to do with command line. Your remote will be the same URL used to clone the repository.

0
1

Warning: This not might be the answer that you are thinking of but it will surely help you get an idea of how things work around here.

Background

I'm also new to Android and the mentor of my course (from which I was learning Android Development) had a habit of creating new projects in Android Studio whenever a new topic started, let it be Java Basics, Intents, Fragments or backendless. I was familiar with Git and it's working. So an idea struck in my head to create a single repository with multiple branches and keep all the projects in respective branches. Quite simple right, but things don't work in that fashion.

Research

I had looked for all the answers on whatever blogs, videos or answers on StackOverflow was present and had tried all the methods. Still, I was not able to get what exactly I wanted. In the Android Studio, when we create a new project, n number of files are created, and all of them are important.

  • I tried to add an existing repository into Android Studio. Firstly we cannot directly add the project into a sub-branch. Secondly, the project will not get merged, I don't know why. Link

  • I also tried to import the existing project into Android Studio. The projects will not contain all the files. Link

Solution

The only solution which I could find was to create a new repository every time and we can upload the changes into it. Believe me, its the best way to keep things organized. Now there comes a problem, with so many repositories, it's hard to keep a track of all of them. So I came up with my own naming conventions for the repositories:

  • Android-Practice-<Project/topic name> - just by the name we can recognize it if we need to refer anything in future and while searching for it, they will all be in a single place
  • Android-Project-<name> - If we are developing our app we can use this, so all projects will be present in a single place.

PS - I like my files to be organized in a proper hierarchy order.

2
  • 1
    Is that a long way of saying you have one repo per project? Commented Nov 11, 2019 at 2:34
  • No @StephenKennedy it's a helpful way of saying that dont make the mistakes which other have made and waste unnecessary time!! Commented Nov 11, 2019 at 15:10

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