today I will share my experience about creating a Git repository for a new Android Studio project.
This post dates back to 2016 and is migrated from an older blog.
My goal is to allow a fellow developer to checkout (Clone in Git words) the project from server and have it fully functional and ready to be run or to work on it and commit changes.
I had to find tiny bits of information sparse around the web ’cause it seems most people consider cool to have any developer configure locally their own project once they first checkout.
Well that is not the only way. Here is what I did.
First of all I chose Bitbucket and not Github because Bitbucket offers free private repository for small teams.
In this way you can share code with your fellow developers even if your project is not intended to go open source.
Setting up a Bitbucket repository
I first created my Bitbucket account signing in with my google account and providing a username and a password.
Once logged in you can select the Repositories menu and create your new repository.
Install Bitbucket plugin for Android Studio
Create the new project you want to add to VCS
Mark file as added to Git
The Gradle build files are not added at this stage but it is essential to add them in order to enable other developers to open a freshly downloaded copy and use it.Change the visualization to: ‘Project‘
Expand the Project node (in this image is the ‘Test’ node), expand the Gradle folder and select the following items (.gitignore file and gradle files):
Now Right click and select: Git –> Add for this files too.
First Commit via Command Line
git remote add origin https://yourtesturepository.git
You can now issue your first commit and then push the content to the central repository you have just set up:
From now on you will be able to commit and push via the GUI integration.
You will always be prompted for the password. Provide it and click enter.
From now on each time you commit via GUI you will se a window like the following, in which you can add a message and specify the author of the commit:
When clicking on commit you still can decide if to commit or ‘commit and push’. In case you choose the second option you will be prompted with a password request.
Saving your credentials
If you do not want to be asked for the password again write the following command and the password will be stored in plain text in the file: .git-credentials
git config credential.helper store
Please be aware that this command creates the file in the user folder and not in the working copy folder.
Then I assume this is not repository specific.
If you want to store it in the global Windows credential management system for better safety
specify another credential configuration method:
git config --global credential.helper wincred
First Checkout by another developer
Note that you don’t have to specify Bitbucket (even if you do, nothing will happen).
Select Git instead and you will be prompted with the following window for repository cloning:
The local Working Copy and Repository will be created and you will be prompted with the following window:
Your answer must be: NO!!! Even Bitbucket tutorial specifies it.
You will find yourself back in the options menu and you will have to select:
Import project, browse to the folder in which you downloaded the project and select the file:
One thought on “Quickly setup Android Studio with Git and Bitbucket”