IntelliJ Idea Integrated with Bitbucket Repository
Tags: intellij, bitbucket, repository, atlassian
Published: 2020-07-05 17:46:34

By the end of this article, you will be able to create a Bitbucket repository and Integrate it with IntelliJ IDE. We’ll see the first time set up process and latter processes. So let’s dive into it.

##What is a Repository?
In software development, a repository is a central file storage location. It is used by version control systems to store multiple versions of files. This may include multiple source code files, as well as other resources used by the program. Branches are used to store new versions of the program.

##What is GIT?
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. I have created a git repository and explained step by step in detail in my last post, you can check it out here — link

##What is Bitbucket?
Bitbucket belongs to “Code Collaboration and Version Control” category, while Git can be primarily classified under “Version Control System”.
Bitbucket is a Git repository management solution designed for professional teams. It gives you a central place to manage git repositories, collaborate on your source code, and guide you through the development flow. It provides awesome features that include: Access control to restrict access to your source code.

##Is Bitbucket free?
Yes! Bitbucket is free for individuals and small teams with up to 5 users, with unlimited public and private repositories. You also get 1 GB file storage for LFS and 50 build minutes to get started with Pipelines. You share build minutes and storage with all users in your workspace.

##How to create a Bitbucket Repository?
Create a bitbucket repo. Go to https://bitbucket.org/ and create a repository by clicking on + symbol in the left pane of the Bitbucket home page.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/k73zd04o8f9560plh3vn.png)

Select the Repository under CREATE options.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/n60na13dsvntd07hde70.png)

Fill out the below details like Workspace, Project name, Repository Name, Access level, Description, Language, and then click on Create Repository.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/6t1bjhtep128wu86o5su.png)

Voila! You have created a bitbucket repository. Now copy the git clone URL and start putting your local code inside our new repository.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/qzes49m4pvigirmwjy8q.png)

Here I’m assuming that you have your local code which you want to push on bitbucket so that others can also contribute to that code. I have written an article, where I have created the Rest assured framework in Eclipse from scratch and pushed it to GIT. You can copy that same framework if you don’t have a local code handy.
Here is that article: {% link https://dev.to/sahiltiwariqa/rest-assured-framework-from-scratch-including-git-repository-integration-for-continous-integration-25hl %}
Here is the repository: https://github.com/sahilTiwariQA/rest_AssuredFramework

In this article, I’m gonna be using IntelliJ for IDE. IntelliJ IDEA is a cross-platform IDE that provides consistent experience on the Windows, macOS, and Linux operating systems. IntelliJ IDEA is available in the following editions: Community Edition is free and open-source, licensed under Apache 2.0.
Eclipse falls short in providing good assistance for code completion despite supporting many plugins. The default code compilation in IntelliJ is much faster and better, especially if you’re a newbie programmer — IntelliJ can help you improve your code.
Open IntelliJ and import your local project from File->Open.
Once you have imported the project in local IDE, let’s enable version control Integration so that we will be able to Push and Pull changes seamlessly in that project.
Go to VCS -> Enable Version Control Integration
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/6hoecmy2ix5ywm3mhl79.png)

Select Git and click OK.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/s5eyi2o2da8k726mtt5h.png)

Now again go to VCS, this time around you will be able to see more options. Add your bitbucket repository by going to Git-> Remotes
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/7kakj9jk7bm03jnyvx91.png)

Click on “+” symbol to add Bitbucket repo URL.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/mxzghbartqev8nrfztek.png)

When you paste the URL, make sure to remove “git clone” command from start of the URL so that your URL starts with “https” and ends with “.git” :
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/dco1bwtz3z3jvs2pg3n2.png)

Enter your Bitbucket credentials for Authentication.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/xmftvx3440tat4kuwznr.png)

Click OK to confirm.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/0jti0ivtx1wnlfx82py4.png)

Now that Bitbucket is connected it will show you a pop-up in Event Log. Click on View Files.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/bjs3cd6b3ca8o7z7ngib.png)

It will show you the whole project to add to Git. Click on Add.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/601bwulrx572hllafgon.png)

Once you’ve added the project, let’s Commit and Push the code to Bitbucket. For that go to VCS->Commit. Since you have not committed any changes before it will open Commit window in the left pane. Give commit message and click on Commit.
Now go back to VCS->Git-> Push
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/cnuw6c8falw7sr920v1g.png)

Check your commit message and all the files and click on Push.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/wzih7952wiwzf38os4ae.png)

Go back to your Bitbucket repository and refresh it to see your Pushed changes in your repository.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/rpi8dxibwd6n3zw0gp2v.png)

Well, you have successfully created a bitbucket repository and pushed your local code into it.

All the above steps are a one-time process except to commit and push steps. Once you have connected IntelliJ to your repository (Bitbucket), you can make changes and commit and push directly from IDE itself. To demonstrate this let’s create a new java class and try to commit and push.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/z2e8t8wdupkmbol5j4we.png)

On the next step, it will ask for Push confirmation. Click on Push and check Bitbucket to confirm if the changes are pushed to the repository or not.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/uuqzpgq6k3xngaxgmzi7.png)

And there you have it! All files updated as expected.