How to connect Android Studio with Bitbucket Git repository across multiple computers

Quickly set up Android Studio with Git and Bitbucket | Connect with git repository in Android Studio
  1. Download and install Git

    You can download Git from multiple sources online or download SourceTree which includes Git from Bitbucket (recommended).

  2. Create a repository on Bitbucket

    Sign up with your email on Bitbucket, then create a repository from the ‘Create a repository’ option at the ‘Repositories’ option found on the website header. Make sure the repository type is ‘Git’.

  3. Invite your team members

    Send invitations of the repository to your team members whether from the repository dashboard invite option or from Settings -> User & Group Access and make sure they can read and write to be able to push and pull files from the repository later.

  4. Make sure your repository is empty

    To move on without errors, you need to make sure that the repository is empty or at least only contains the readme file, you can check this from the Bitbucket account at the ‘Source’ option.

  5. Enabling versions control on Android Studio

    Whether you have an existing Android Studio or starting a new project, you should enable versions control in them. Go to VCS drop down menu at the top of your Android Studio screen, then click on ‘Enable Version Control Integration’.

  6. Setting the version control system to be Git

    After clicking on the Enable Version Control Integration, a new form will be opened. Choose Git from the drop down list of the version control system and then click ‘Ok’.

  7. Add the project files to Git

    Right click on the application item – that includes all the application files except the Gradle – from the project panel. Click Git then choose add.

  8. Setting up your user information

    Click on the terminal panel to open the terminal of the Android Studio, then add the following commands with your information:  git config –global ‘YOUR NAME’ git config –global ‘YOUR EMAIL’. (See How to Connect VR Box to PC?)

  9. Copy the repository HTTPS URL

    Go to your repository on the Bitbucket account on your browser. At the overview panel, copy the repository HTTPS URL at the top right of the panel. Make sure to select HTTPS URL not SSH, HTTPS protocol will only be covered in this summary, SSH is a more secured protocol that might require more steps.

  10. Connect the Android Studio to the repository

    Go back to the terminal on the repository, and write down the following commands with the URL you just copied on the second line: git init
    git remote add origin YourCopiedRepositoryURL

  11. Clone the empty repository to your folder

    Write the following commands in the terminal on Android Studio:  git init git pull origin master –allow-unrelated-histories

  12. Commit and push with the terminal just this time.

    Write down the following commands in the Android Studio terminal to commit and push the project to the repository:  git add –all
    git commit -m ‘initial commit’
    git push -u origin master

  13. Prepare your team mates to pull from the repository

    To let your team mates pull the project, they have to repeat step 9, then create an empty folder locally where they want to have the project cloned into.

  14. Clone to pull the project for the first time from the other PC

    Your team mates should go to the Android Studio, click on VCS menu -> Checkout from Version Control -> Git. Then they should paste the HTTPS URL of the repository into the ‘Git Repository URL’ text field. Finally, they should choose their parent directory to be the empty folder they created earlier.

  15. Sync if needed

    If syncing errors show up, let the Android Studio sync and update all what it needs to make a successful clone.

  16. Enjoy committing, pulling and pushing from the Android Studio

    You can commit, push, pull, merge and resolve code conflicts easily from Android Studio with team mates at this point. Just make sure to commit, push or pull whether from the ‘Commit changes’ and ‘Update project’ buttons on the Android Studio or Git option menu from the VCS menu. (See How to connect Bluetooth Headphones to your Android device?)

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts