Using BitBucket with PyCharm

Introduction

I’m working on a critical software and wanted to have private repositories so that only I can have access to those repositories. Even though GitHub is the most popular repository hosting service, unless you pay for the repositories you create they will be considered as public repositories and it’ll be available for all to see. Didn’t want to spend a fortune on GitHub to create private repositories, so was looking for other alternatives and found out that BitBucket is an excellent option.

BitBucket provides unlimited private repositories and is free.

The following steps have been tested on Windows 10 machine running PyCharm 5 Professional Edition with Python 3.5 interpreter. These steps should work in PyCharm Community edition as well.

I assume that you already have a working copy of PyCharm (Professional/Community Edition) configured with Anaconda Python Distribution. Otherwise, you can follow the tutorial at http://bit.ly/1WE5xqn to get your PyCharm up and running.

Steps Involved to Configure PyCharm to use with BitBucket

Following are the steps to be followed to configure PyCharm to use with BitBucket.

Step 1:

Go to the URL https://bitbucket.org and register for yourself by providing proper information.

1

Step 2:

Go to this URL https://bitbucket.org/dmitry_cherkas/jetbrains-bitbucket-connector/downloads and download the latest version of Jetbrains BitBucket Connector plugin and unzip it. We have to make use of this plugin to configure PyCharm with BitBucket.

2

Step 3:

For demo purpose, I have created a PyCharm project called BitBucketPyCharmDemo and a python file as Demo.py. In the right pane of the editor I have written the following code

print(“Hello BitBucket”)

3

Step 4:

Now go to File => Settings

4

Step 5:

On the left pane of the Settings window, Click on Plugins => Click on Install plugin from disk button and browse to the folder where you have unzipped the downloaded plugin from Step 2 and click on bitbucket.jar file and click OK button. Again click on Apply Button. At this stage you have the BitBucket Plugin installed on your system.

5

Step 6:

Now go to Other Settings in the left pane. Click and expand Other Settings and click on Bitbucket.

Give the Login and Password that you used to register at Bitbucket in Step 1.

Click on Test button. If you have supplied proper information then a window will be displayed saying Connection Successful.

6

Step 7:

At this stage go to https://desktop.github.com/ and download GitHub Desktop software and install it. It’ll take sometime to install. Ensure that you are connected to internet.

Once the software is installed then browse to the path where git.exe is found.

You have to specify the entire path along with git.exe.

For e.g.,

C:\Users\UserName\AppData\Local\GitHub\PortableGit_c2ba306e536fdf878271f7fe636a147ff37326ad\bin\git.exe

To see whether the git has been configured properly or not, click on Test button.

You should see a message saying Git executed successfully.

7

There are few additional steps that needs to be carried out at this stage. Go to Control Panel => System and Security => System. Click on Advanced system settings on the left pane.

30

In the System Properties window click on Environment Variables button.

31

In the Environment Variables window click on the Path System variable and then click on Edit button.

32

In the Edit environment variable window, click on New button and paste the path where git.exe is present (exclude git.exe from the path) and click on OK button.

For e.g., C:\Users\UserName\AppData\Local\GitHub\PortableGit_c2ba306e536fdf878271f7fe636a147ff37326ad\bin\

33

Now open the command prompt and type git.exe. If everything is configured properly then you’ll see a series of messages in the command prompt.

Step 8:

Now go to VCS in the menu => Select Enable Version Control Integration

8

Step 9:

You will be asked to select a version control system to associate with the project root.

Select Git from the pull down menu.

9

At the bottom of the editor you will see a message saying that Git repository has been created.

10

Step 10:

This step is very important.

If you have not logged into bitbucket.org then give your credentials and log in to bitbucket.org.

In the menu, click on Create and select Create Repository.

In the Name Textbox provide the same name as that of the Python Project which you have created.

In our case, we had created PyCharm project as BitBucketPyCharmDemo, so we’ll provide the same name.

Select the checkbox for Access level indicating that this is a private repository.

Click on the radio button Git for the Repository type.

Click on Create Repository button.

11

Step 11:

You will be taken to a screen as shown below. Expand the link, I have an existing project and copy the second line as shown in the below screenshot.

git remote add origin https://bitbucketpycharmdemo@bitbucket.org/bitbucketpycharmdemo/bitbucketpycharmdemo.git

12

Step 12:

In your PyCharm editor, click on the Terminal button found in the bottom pane.

Paste the path which you had just copied from the previous step in the Terminal Window and press Enter.

If the step is successful then you’ll not see any output.

13

Step 13:

Click on the python file. In our case it is Demo.py.

Then, go to the Menu and select VCS => Git => +Add

14

Step 14:

Go to VCS => select Commit Changes

15

Step 15:

You will be presented with below screen. In the Commit Message window, type First Commit.

Click on Commit button and select Commit and Push.

16

Step 16:

Click on Push button

17

Step 17:

You’ll be asked to enter the BitBucket login password.

Provide the password and check the Remember checkbox.

Click on OK button.

18

Step 18:

At this stage, you will be asked to Setup Master Password. It is highly recommended that you enter a password. You need to remember this password. Setting up of this Master Password happens once. On subsequent creation and upload of other projects to BitBucket, you will be prompted to enter this master password.

18_1

Step 19:

On completion of the previous step, the python file will be uploaded to the repository. If you want to see the file then login to your BitBucket account with your credentials.

Click on your repository name, then selct Source link found in the left pane.

As you can see in the below screen, the file Demo.py has been uploaded.

19

If you want to see the contents of the file, click on the file name.

20

Step 20:

What if you want to change the contents of the file and see the same to be reflected in your online repository?

Type the below line in the editor

print(“This is second Commit”)

We have modified the file.

Now go to VCS => Commit Changes

21_1

In the Commit Changes Window, write Second Commit in the Commit Message window and click on Commit button and select Commit and Push.

21

Click on OK button.

22

Step 21:

Lets do some changes and commit the contents again.

Type the following line in the editor

print(“This is Third Commit”)

Go to VCS => Click on Commit Changes

23

In the Commit Message window, type Third Commit.

Click on Commit button and select Commit and Push option as shown below.

24

Click on Push Button.

25

Step 22:

Click on the Demo.py file and see that all the latest changes have been committed.

26

Step 23:

What if you want to revert back to previous code or want to see how the code has been changed during various stage of commitments?

Go to menu. Select VCS => Select Git => Select Show History

27

In the bottom window of the editor, an history of all the commitments made for the project is displayed.

If I want to see the code during the first commit, right click on the First Commit and select Jump to Source.

28

A separate Tab will be opened and you can see code that was written during the First Commit.

29

Conclusion

This article shows the various steps involved in configuring PyCharm to use with BitBucket. I wrote this article as I could not find all the information related to configuration of PyCharm to use with BitBucket in one place.

After lots of hard work(like trial and errors, reading various blogs, watching YouTube videos), I found the proper way of configuring.

Hope this helps someone out there.

I would like to give credit to various blogs and resources from where I stitched all this information.

Comments

  1. Thanks for this. I’m new to programming and I’ve already gotten myself into trouble by not having VCS and your tutorial was extremely helpful. The only issue I ran into is there are multiple bitbucket connectors. The one I tried to download directly from PyCharm 5 did not work. I had to go to another Repo by Dmitry Cherkas and that connector worked correctly.

  2. Thanks for the tutorial, however I’m stuck on step 12. I cannot run git.exe from terminal (in pycharm), even though I have confirmed that the path (in step 7) is correct.

      1. Thanks, All good now (didn’t even think about the OS path).
        With step #7 in W7, you can edit the path without having to perform the last step that you mention there { ie In the Edit environment variable window, click on New button and paste the path where git.exe is present (exclude git.exe from the path) and click on OK button.”}. Thought I’d mention that for anyone else that may come across it.

        1. It’s also useful to note that with the current version of PyCharm you must restart pycharm before it recognizes new environment variables. You also have to restart it after installing the plugin, or you won’t have the ‘Other Options’ in settings. Other than those small issues, this guide is outstanding.

          Thank you for the guide Dr. Gowrishankar

Leave a Reply to Michele Russo Cancel reply

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