Skip to main content

Importing a project into Bitbucket repository from Android Studio

· 3 min read

Android Studio can directly work with Github, but not with Bitbucket. Instructions for pushing an project into a Bitbucket repository for the first time are very confusing, and this process can become very frustrating if the right steps are not followed. Basically, you have to know that your first commit must be manually executed instead of using an option from the main menu or from popup menus.

In this post, we are going to use Android Studio version 1.4.

First of all, you have to create a new repository in Bitbucket, for example, AndrodStudioBitbucketTest.

In the picture above a couple of git commands have been highlighted because they are going to be used later.

Next, create a new project or open an existing project in Android Studio. Then, in order to add your project to a Git VCS, go to VCS menu and select Enable Version Control Integration... as in the following images are shown

Note that archives are now in brown color.

This operation is equivalent to a git init command. You can check it in the Console panel of the 9: Version Control view.

Next, clicking on the Terminal button at the very bottom of the window you will get into a console of the operative system. By default, the terminal opens at the location of your project. Now, execute the first command highlighted before in order to add the URL of the Bitbucket repository as a remote to your local repository.

You can now execute git remote -v to show the URLs that Git has stored for the short name to be used when reading and writing to the remote. By this way, you are sure that the remote add command has been successfully executed.

If you now click on VCS button or on Commit Changes... option, you get the message: Nothing to commit. No changes detected

This message is shown because you have not added files to be commited. To add files, right click on the main project node and select Add

Note that files are now in green color. You can also check the command git in Console panel.

In theory, if you click on Commit Changes botton and then on Commit and Push, as in the following image is shown

you should have the files pushed. However, this operation did not work, at least for me.

So you have to execute the first commit of your repository by hand from terminal view. You have to execute the git add command as it was highlighted in the second image of this post. Be careful: in Windows, replace simple quotations marks (') by inverted commas ("), because if not, you will get the error

error: pathspec 'commit'' did not match any file(s) known to git.

The result of commit command is:

Now you can push the files as in the following images are shown:

Now, check in Bitbucket your list of commits:

From now on when you go to the VCS menu and press Push it will upload to the Bitbucket repository. If you want, you can now install Bitbucket plugin for Android Studio (https://plugins.jetbrains.com/plugin/6207?pr=androidstudio) and use it with your commits and pushings.