Uploading Android Studio project to Bitbucket using Git
I had some trouble uploading a new project to Bitbucket in Android Studio recently. I found the solution was simple and obvious when I looked in the right place.
First of all, I know that Github is more popular for central version control management but I am learning to develop apps and I don't want to learn in public, as Github doesn't have any free private repositories. Bitbucket does. Also, Bitbucket seems to be a very reliable service. That explains my choice of services. I started using Bitbucket with Mercurial but since they now support Git, which is the main VCS out there I decided to switch.
Anyway, I had trouble finding instructions on getting Android Studio's built in Git control to talk to Bitbucket. Here are the steps I found after days of working on it. (I am not doing this full time, so I only spent a few hours a day on it. Still it was frustrating.)
First, set up a new repository on Bitbucket. The most important setting here is to use Git. Mercurial works as well, but I am not covering that here.
Second, once the new repo is set up on Bitbucket, there will be a link that says "I have an existing project to push up." Click that link. There will be some instructions with a set of terminal commands on the page.
Next, go to Android Studio and add your project to a Git VCS. In the VCS menu go to Git and select "Add to VCS." This will create a local Git repository that we will then upload (push) to Bitbucket.
Next, access the terminal in Android Studio by clicking on the Terminal button at the very bottom of the window. This opens the terminal at the location of your project. If you read the instructions on the Bitbucket site you would see that the first command was to get you into this directory. I found this way easier.
Now copy the last three command lines from the Bitbucket website to the terminal window in Android Studio. Do each one individually. These lines add the URL of the Bitbucket repository as a remote to you local repository. Then this pushes what is already there to the website.
That is all. From now on when you go to the VCS menu and press Push it will upload to the Bitbucket repository. I did this on a Mac so the terminal commands may be a little different on Windows.
First of all, I know that Github is more popular for central version control management but I am learning to develop apps and I don't want to learn in public, as Github doesn't have any free private repositories. Bitbucket does. Also, Bitbucket seems to be a very reliable service. That explains my choice of services. I started using Bitbucket with Mercurial but since they now support Git, which is the main VCS out there I decided to switch.
Anyway, I had trouble finding instructions on getting Android Studio's built in Git control to talk to Bitbucket. Here are the steps I found after days of working on it. (I am not doing this full time, so I only spent a few hours a day on it. Still it was frustrating.)
First, set up a new repository on Bitbucket. The most important setting here is to use Git. Mercurial works as well, but I am not covering that here.
Second, once the new repo is set up on Bitbucket, there will be a link that says "I have an existing project to push up." Click that link. There will be some instructions with a set of terminal commands on the page.
Next, go to Android Studio and add your project to a Git VCS. In the VCS menu go to Git and select "Add to VCS." This will create a local Git repository that we will then upload (push) to Bitbucket.
Next, access the terminal in Android Studio by clicking on the Terminal button at the very bottom of the window. This opens the terminal at the location of your project. If you read the instructions on the Bitbucket site you would see that the first command was to get you into this directory. I found this way easier.
Now copy the last three command lines from the Bitbucket website to the terminal window in Android Studio. Do each one individually. These lines add the URL of the Bitbucket repository as a remote to you local repository. Then this pushes what is already there to the website.
That is all. From now on when you go to the VCS menu and press Push it will upload to the Bitbucket repository. I did this on a Mac so the terminal commands may be a little different on Windows.
Comments
I'd been banging my head against the wall on this for a while - your description was just the job!
I did this on Windows, only issue I had was that I had to add the directory containing my git.exe to my PATH environment variable for the git command to work in the built-in terminal.
Much obliged!
Cheers,
Jason
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
Everything up-to-date
Sumit, if I understand correctly that error indicates that the remote repository and the local repository histories don't match, meaning that something was changed at the remote repository since you pulled from it. Make sure that you are starting with a fresh repo on Bitbucket, or you can force it by adding -f to the push command. This will force the update and may erase anything that is already there so BE SURE YOU WANT TO DO THAT if you use the force flag.
and the repository exists.'
Since I'm new to git I didn't realize I needed to set up an ssh key first to avoid this error, so I figured it'd be good to post it here for anyone who comes across this in the same boat as me.
And here's the information to solve that problem: https://confluence.atlassian.com/display/BITBUCKET/Set+up+SSH+for+Git
Thanks for the information! This makes more sense to me than the bitbucket plugin for IntelliJ IDEA, though I didn't give it much of a chance when it didn't work as I expected right off.
You have to add files to your repository before you can push. This will solve the error "No refs in common and none specified; doing nothing...."
I did git add ../ and it solved it. So after that i was able to move on.
https://bitbucket.org/site/master/issue/9284/cant-push-project-to-bitbucket
1. Before copy pasting the push commands, first execute git add . (or ../ depending on which directory you are in when you open the terminal)
2. Then run the command git commit -m "Initial commit".
Again, thanks to the other comments to your blog, I could figure this out easily.
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
Everything up-to-date
The solution is to run these command first (In the terminal):
---Note, these create the master/remote master branch for you then you can commit/push!
1. git init .
2. git checkout -b master
3. git commit -am "first commit"
4. git push -u origin --all
Troys-MBP:Resume Template Pro troychuinard$ git push -u origin --all # pushes up the repo and its refs for the first time
conq: repository access denied.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I am getting issue that,after follownig all these steps I am not able to push new changes to BitBucket because android studio is still configured with github repo. that I have deleted.?
I waiting for your reply.....