In this article we are going to take a little break from writing quantum algorithms to spend some much needed time on our coding setup.

Installing Git

Open Oracle VM VirtualBox and start your Quantum Virtual Machine. Once it has loaded, press Ctrl+Alt+T to open up terminal. Open Firefox briefly to ensure that you have access to the internet.

In Terminal, start by updating the package manager just in case it has gone out-of-date between virtual machine uses, type:

$ sudo apt update

Now run the following command to install Git

$ sudo apt install git

Verfiy the installation by typing the following command

$ git --version

Figure 1 – Verifying that Git is installed

Using Git with your Python Source Files

Now go to your Python environments folder

$ cd py_envs

and activate the Quantum virtual environment with

$ source Quantum/bin/activate

Figure 2 – Activating the Quantum virtual environment

Check that git is recognised from within the virtual environment with the following command:

(Quantum) $ git --version

Check to ensure that pip is working from within the virtual environment with the following command:

(Quantum) $ pip --version

Initialise an empty Git Repository (repo) in the Quantum virtual environment by first changing directories

(Quantum) $ cd Quantum
(Quantum) $ git init

Figure 3 – Initialising an empty Git Repository inside the Quantum virtual environment. Note that we have both activated the VE and we have navigated to inside the folder before executing the Git initialisation.

This will place a .git folder inside the Quantum virtual environment folder structure. Change directory to this folder to view the basic skeleton structure of an empty Git Repo:

(Quantum) $ cd .git/

Figure 4 – The folder structure of an empty git repo.

We now need to add the Quantum VE to the gitignore

(Quantum) $ echo 'Quantum' > .gitignore

This keeps the virtual environment out of source control.

Creating a Dependency File

Now type in the following to create a dependency file:

(Quantum) $ pip freeze > requirements.txt

This will also create a new text file inside the ~/py_envs/Quantum/.git folder.

Figure 5 – Creation of the requirements text file, i.e. the folder which contains all of the dependencies.

If you have vim installed, you can view the text file in Terminal with either

(Quantum) $ vim requirements.txt
(Quantum) $ nano requirements.txt

Figure 6 – Opening the requirements text file shows a list of all the dependencies of your Virtual Environment.

Close the text editor and go back one directory to the Quantum VE folder. Type in

(Quantum) :~/py_envs/Quantum$ git status

Figure 7 – Checking the Git Status

This is correctly showing the list of Python source files that it is keeping track of!

Let’s add our pip requirements (dependencies) file to this repo with the command:

(Quantum) $ git add requirements.txt


(Quantum) $ git status

Figure 8 – Note the green text at the top indicating that there is a new file to commit to the repo!

We can force Git to track all of our files by typing in

(Quantum) $ git add .
(Quantum) $ git status

Figure 9 – Argh! Now all of our files are added and being checked for updates in the Git repo! That’s way too many, we just want our Python files (which you can see at the end there).

This won’t work, because now git wants to track all the files in the VE, including Python’s site packages! According to my environment, that is over 19,000 files!

Git Reset

To reset the Git state, type in:

(Quantum) $ git reset
(Quantum) $ git status

To check that it has un-added all the files.

Let us check in the files we need one-by-one.

(Quantum) $ git add requirements.txt
(Quantum) $ git status

It shows the requirements text file as a change to be committed.

Git Commit

Go to and sign in. Remember your email address.

Go back to Terminal and type in

(Quantum) $ git config --global ""
(Quantum) $ git config --global "yourname"

Now you can commit your changes with:

(Quantum) $ git commit

Let us commit this file with a message:

(Quantum) $ git commit -m 'Added requirements.txt'

Figure 10 – Added a single Requirements text file to git repo.

Git Log

We can also view this change in the Git log by typing in:

(Quantum) $ git log

Note that the commit status is (HEAD -> master). This means that our changes are still in our local environment. So now we need to push it to our GitHub repository…


Creating a GitHub Repository

Go to Sign in using the same email address that you used above to configure your Git repo. On the right hand side, click the + button and add a new repository. Give the repository a name (I call it the same name as the virtual environment). Leave the description blank, set it to public and tick initialise with a README. Don’t add any ignores or licences at this stage, click Create Repository.

Figure 11 – Creating a new GitHub Repository

At the top of the new GitHub repository <> Code page (the default landing page after creation), find the Quick Setup area and note the HTTPS URL. It should say something like:[YourNameHere]/Quantum.git

Note that your name and your repo name in the above URL should match exactly the git config name and virtual environment.

Now add the URL for the repository by typing in

(Quantum) $ git remote add origin '[YourNameHere]/Quantum.git'

Verfiy the new remote by typing

(Quantum) $ git remote -v

Push Commits to GitHub from Quantum Virtual Environment

The push commits to GitHub from the Quantum Virtual Environment simply type in

(Quantum) $ git push origin master

And enter your GitHub repo account name and password.

Figure 12 – Pushing code commits to GitHub Repository. Note, we are currently only pushing the Requirements Text file.

Go back to GitHub website and hit Refresh on your browser.

There should be a new file there called Requirements.txt.

Figure 13 – Successfully committed the Requirements text file from a Virtual Environment within a Virtual Machine running Linux Ubuntu in to a GitHub repository.

There we have it, we have successfully committed our first file from our Linux/Ubuntu virtual machine in to our remote GitHub repository.

Linking PyCharm to Git

Go back to your Terminal which is already in the Quantum VE and open PyCharm

(Quantum) $ PyCharm

When it loads, give it a minute to index (wait for the bar down the bottom to go to 100%). The first thing you should notice is that it has recognised that the virtual environment has a Git repo running in it, because all source code files should be red with the exception of the requirements.txt file:

Figure 14 – With Git running in the Quantum virtual environment, PyCharm correctly displays which files have been added (grey) and which ones are not being tracked (red).

To get a Python file in to your GitHub follow these steps:

  1. Type (Quantum) $ git add [FileName].py
  2. Type (Quantum) $ git commit -m 'Added [FileName] to GitHub'
  3. Type (Quantum) $ git push origin master
  4. Watch as [FileName] turns from red to white in PyCharm.
  5. Watch as a new file is added to GitKraken or GitHub.

Getting  the .gitignore File Just Right

OK, so everything was going well at this point, however it was annoying to have to go through each Python file in my project one-by-one and git add/commit/push each one. It would be nice if I could just go

(Quantum) $ git add .

and add all my Python files.

Also, PyCharm was still showing several subfolder as red, which meant that if I did a git-add-all command, thousands and thousands of files would get added to the git head.

So I created a .gitignore file in my Project folder. It appeared in PyCharm along with my other Python files. I opened it with PyCharm and edited the blank file. I made it look like this:

Figure 15 – I went  through and added each and every folder manually which I didn’t want hooked up to my GitHub. Saving this file turned all my important Python files green. Now I can git-add-all and not worry about committing a heap of system files to my GitHub.

At this point I noticed that PyCharm’s Version Control pane down the bottom was useful (Alt+9 to open). It immediately showed that my .gitignore file was changed and was glowing blue. So I right-clicked it and clicked Commit, filled out the form, and click Commit.

Now my .gitignore file was up on GitHub.

Suddenly all my important files in PyCharm were green and the ones I didn’t on GitHub were greyed out.

Alternatively you can go to and enter PyCharm, Python and venv in to the Create bar.

Committing Multiple Files to Git

Now that I had my .gitignore file sorted out I was free to go back to the Terminal and use

(Quantum) $ git add .

Alternatively, I could use PyCharm’s VSC interface to commit multiple files by clicking on the VCS menu in the ribbon and clicking Commit (Ctrl+K). In the Commit Changes window that pops up I can see 12 green python files with tick-boxes (this is much better than the list of 19,000 files I had before I sorted out my .gitignore file).

I ticked all them and entered a message: “First bulk commit”. Then I clicked Commit.

Now that I have committed everything that isn’t in my .gitignore list, when I type

(Quantum) $ git status

in Terminal it says

On branch master nothing to commit, working tree clean

Pushing Multiple Files to Git

You can also push from PyCharm by going VCS > Git > Push or holding (Ctrl+Shift+K). In the Push Commits window that pops up click Push. Enter your GitHub username and password and click Push. You should get a message saying that several files have been successfully pushed to GitHub.

Back in PyCharm everything is back to White, this is what a clean working tree looks like:

Figure 16 – A clean working tree.

Meanwhile, over in GitKraken land…


Open GitKraken. Click Sign-in with GitHub. Once it is logged in, click Open a repo. In this view of your repo


Click Create New Glo Board. Enter a board name (E.g. QuantumComputing) andenter a board group (E.g. My Boards). Click the green Connect to GitHub button in the bottom left-hand corner.

Click Create Board.

Now click and create three new columns: “To Do”, “In Progress” and “Completed”.

Figure 17 – Creating a basic glo board.

Now let’s add a card in the To Do column called “Test Superdense Coding”, then let’s create two more there called “Test Quantum Teleportation” and “Perform Bell’s Inequality Test”.

We can click on the “Test Superdense Coding” card and fill out some of its properties on the right hand side:









My Virtual Machine Has No Internet Connection

There was a point where I opened up my Virtual Machine only to find that it suddenly did not have internet connection.

First I checked that Devices > Network > Network Settings > Adapter 1 was enabled and attached to NAT. But, of course, it was because I had changed nothing and it was working the last time I used the machine.

I tried shutting down the machine and rebooting it and that seemed to work.

See here for more information.

Could Not Get Lock Error

I was trying to install Git in to my virtual machine but kept getting the

E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)

E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?

After trying a few things I found this question asked here which tells me to execute the following commands one-by-one in Terminal:

$ sudo killall apt apt-get

$ sudo rm /var/lib/apt/lists/lock
$ sudo rm /var/cache/apt/archives/lock
$ sudo rm /var/lib/dpkg/lock*
$ sudo dpkg --configure -a
$ sudo apt update

After this, I ran $ sudo apt install git and it worked.

See here for more information to this problem.