77

So basically I have an Android Studio project on my local computer and I need to add it into my BitBucket repository I created online. I just can't get it right with Android Studio. I can't upload files from Android Studio project to my BitBucket repository.

How can I do such a thing?

Zoe
  • 27,060
  • 21
  • 118
  • 148
Muhamed Krlić
  • 1,462
  • 2
  • 16
  • 25
  • 1
    I found that, after 1 year of experience with git, It's best to use git bash ( terminal ) to preform all git operations. Including the one regarding in this question I posted. – Muhamed Krlić Jun 13 '15 at 19:37
  • 1
    http://www.praveenboyalapalli.com/2017/03/how-to-push-project-source-code-to-bitbucket-repository-from-android-studio/ – Rasel Oct 26 '17 at 07:30
  • Check this link to import android project from BitBucket:- http://www.learnwithmindscript.in/blog/user/blog_details/3 – Nikhil Pawar Jan 17 '19 at 16:15

7 Answers7

110

Here is how I did it without plugins:

  1. Create the repository on your Bitbucket account

  2. Create your project in Android Studio

  3. In Android Studio, Go to VCS

  4. Choose 'Enable version control'

  5. Choose Git and press OK

  6. Right click on your project, choose Git then click Add

  7. Open Terminal in Android Studio

  8. Go to your Bitbucket repository Overview

  9. Click on 'I have an existing Project'

  10. Copy the 'git remote add origin ... etc.' line to your terminal and press enter

  11. Click on 'Commit Changes', write your comment then press Commit and push

Also add the 'git push -u origin master' in the terminal at part 10 of above

Zoe
  • 27,060
  • 21
  • 118
  • 148
Matrix
  • 1,810
  • 1
  • 19
  • 20
  • error `Push rejected: Push to origin/master was rejected` – user924 Sep 09 '17 at 15:41
  • Perhaps its better to do 11 'Commit Changes' with commit only and 12 'git push -u origin master' in terminal – georgij Oct 28 '17 at 05:27
  • 4
    I'm following this for the first time and after part 10 got "error: src refspec master does not match any." Instead I did 11 - commit changes and then did 10 and it worked fine. – Lewis Black Dec 01 '17 at 16:29
  • Also remember that when you create the repository that you should say no to making the readme file, cuz it messes up everything – kyay10 Feb 04 '19 at 22:20
  • 1
    When doing step 1. NEVER CREATE a "READ ME FILE". That can mess up your whole year!!! trust me! – The Billionaire Guy May 06 '20 at 07:14
11
  • In the Android studio, go to VCS-> 'Enable version control'.

From dropdown menu select Git, then click OK.

  • Right click on your Project view in the Android Studio:

go to Git -> Add.

(All the files in the project should change the color, turned green probably)

  • Open Terminal in the Android studio.

From your empty repo in the Bitbucket page, copy from the paragraph "Step 2: Connect your existing repository to Bitbucket" the line :

git remote add origin https://<user>@bitbucket.org/<path>.git, then Enter.

Now type:

git commit -m "initial commit" (to commit all the files from the Project), then Enter.

Now type:

git push -u origin master (to push all the commited files to the master- or the other branch, just change "master" to other branch).

That's it. Your project is versioned and placed in your Bitbucket repo.

androidEnthusiast
  • 1,140
  • 1
  • 12
  • 21
10

Heres is what i did without plugins

Already have a project in Android Studio

1- Create the repository on your Bitbucket account

2- In Android Studio, Go to VCS

3- Choose 'Enable version control'

4- Choose Git and press OK

5- Right click on your project, choose Git then click Add

6- Go to VCS -> Commit Changes

7- Uncheck 'Perform Code Analysis'

8- Press Commit and Push in the Commit button

9- A new window will open, on the left press the DEFINE REMOTE link

10- Go to your Bitbucket repository Overview

11- Click on 'I have an existing Project'

12- Copy the link from bitbucket to the URL tab in the Define Remote Window ,e.g. 'git@bitbucket.org:username/project.git' without the 'git remote add origin...' (maybe it will ask you for a password of your bitbucket account), press Ok

13 Press Push, and it's done

borissoto
  • 116
  • 2
  • 4
  • 2
    Also remember that when you create the repository that you should say no to making the readme file, cuz it messes up everything – kyay10 Feb 04 '19 at 22:23
  • 1
    BitBucket now also offers to create a `.gitignore` file as well. You should decline that too, you need an **empty** repo with nothing in it whatsoever. Once you have created your empty repo, BitBucket will go to the Source tab automatically and provide you with instructions on how to add your existing code to BitBucket. See @androidEnthusiast's answer when you've got this far. – Adrian Wiik Apr 12 '21 at 21:20
5

If you want to use Android studio without the use of console/terminal. Use below steps to create a new project in Bitbucket.

  1. Go to VCS in Android Studio

  2. Choose 'Enable version control'

  3. Choose Git and press OK

  4. Right click on your project, choose Git then click Add

  5. Create the repository on your Bitbucket account

  6. Go to your repository in Bitbucket, Copy the https url

  7. Go to Android studio project -> Git -> Repository -> Remotes

  8. Add a new entry with value of https link received from step 6

  9. Android studio -> your project -> Git -> Commit Directory -> Commit & Push

Make sure you define your .ignore file to avoid unnecessary items being copied to bitbucket

Kaps
  • 2,345
  • 2
  • 26
  • 37
2

Easiest way is to clone your empty repo with standard "git clone git@bitbucket.org:projectNameAndLocation.git". So let's clone it to the location, as example, user/newAndroidProject.

Create an emtpy Android project from Android studio (let's call it just AProject), in case you don't have one.

Now copy all the files from your new Android project root directory(everything from AProject folder) or just copy all the files from your existing project root directory into the location where your empty repo directory is (into the newAndroidProject folder as example). So everything from AProject>, goes in the newAndroidProject>.

All the files will be automatically added under the git, inside this repo folder. You can open then for example in the SourceTree your "newAndroidProject" and you will see all the files there and then just push everything to the origin (after you edit your .gitignore file of course).

androidEnthusiast
  • 1,140
  • 1
  • 12
  • 21
1

From Android Studio, go the the VCS menu on the menu bar and select Import into Version Control, select which VCS you want to use ie: Create GIT repository.

wyoskibum
  • 1,869
  • 2
  • 23
  • 43
0

The BitBucket plugin didn't work with me. However I was able to clone the repository by coping the https url and pasting it in Android Studio then enter the username and password and it should be able to clone it.

m4design
  • 2,112
  • 3
  • 21
  • 28