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.
Go to the URL https://bitbucket.org and register for yourself by providing proper information.
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.
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
Now go to File => Settings
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.
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.
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.
To see whether the git has been configured properly or not, click on Test button.
You should see a message saying Git executed successfully.
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.
In the System Properties window click on Environment Variables button.
In the Environment Variables window click on the Path System variable and then click on Edit button.
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\
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.
Now go to VCS in the menu => Select Enable Version Control Integration
You will be asked to select a version control system to associate with the project root.
Select Git from the pull down menu.
At the bottom of the editor you will see a message saying that Git repository has been created.
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.
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://email@example.com/bitbucketpycharmdemo/bitbucketpycharmdemo.git
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.
Click on the python file. In our case it is Demo.py.
Then, go to the Menu and select VCS => Git => +Add
Go to VCS => select Commit Changes
You will be presented with below screen. In the Commit Message window, type First Commit.
Click on Commit button and select Commit and Push.
Click on Push button
You’ll be asked to enter the BitBucket login password.
Provide the password and check the Remember checkbox.
Click on OK button.
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.
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.
If you want to see the contents of the file, click on the file name.
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
In the Commit Changes Window, write Second Commit in the Commit Message window and click on Commit button and select Commit and Push.
Click on OK button.
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
In the Commit Message window, type Third Commit.
Click on Commit button and select Commit and Push option as shown below.
Click on Push Button.
Click on the Demo.py file and see that all the latest changes have been committed.
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
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.
A separate Tab will be opened and you can see code that was written during the First Commit.
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.