Photo by Lukas from Pexels

A quick workflow for Google Colab, Github and Jupyter notebooks on Mac.

Alexander Beat
Analytics Vidhya
Published in
6 min readAug 24, 2020

--

I have an older ’09 Macbook Pro and had trouble while trying to run the latest Keras to use for my latest Flatiron school neural network projects. The older Mac only updates to El Capitan, so it’s unable to run the latest versions of Keras in Jupyter notebooks. To get around this, I have been trying to integrate the use of Google Colab with my workflow. Colab is a cloud-based notebook and has the needed updates to run Keras and has come in handy. Trying to learn the small differences between Jupyter notebooks and Colab in order to keep everything flowing smoothly and all my changes synced has been challenging. Here is a little workflow that I’ve found useful in managing my notebooks and Github repositories. It’s not the most elegant but I have found it to be useful and it gets the job done for now, while I continue to learn more about using Colab and all of it’s connections to Github.

1. Create a repository in Github.

If you already have a repository you want to work with, then move to step two of this process to create or open a Colab notebook. If you need to make a whole new repository to start with, go to Github and create a new one. Click the green “New” button under the repository section.

Click the green button to create a new repo.

Add a name for the repository on the next screen, and click the box to initialize a README. You can choose to add a license to the repository, though I am still learning about all of the different types there are and won’t go into detail about that in this article. Here’s a good link I found about the differences between some of them for you to check out. https://www.fastcompany.com/3014553/what-coders-should-know-about-copyright-licensing. Then click “create repository”.

The next screen will be a sort of blank slate repository which shows your README file which you can leave alone for now and head over to Google Drive.

2. Create or open a Colab notebook in Google Drive.

In Google Drive, click the “New” button, go to “More” and select “Google Colaboratory”. If Colab doesn’t show up in this drop down, you should be able to find it by clicking on “Connect more apps”.

Click New.
Go to More.
Click Google Colaboratory.

A new Colab notebook tab will open. This will serve as your new notebook to work with and eventually save to your Github repo. If you already had an existing repo and notebook and would like to open it in Colab, on the top menu bar click “File”, “Open notebook”.

Click Open notebook.

A new pop up will appear. Click “Github” on the top. You may need to enter your Github credentials here to connect to Colab if you haven’t already done so in the past. If it’s connected you should see a screen like this, showing your Github username in the search bar. Make sure you have the check the box “Include private repos” in case your existing repo is not public. A dropdown menu of your repositories will be underneath and you can select the one you created. Once selected, if you had an existing notebook on the Github repository it should show up underneath and you can click on that to open it in a new Colab tab and continue to work on it.

The existing notebook shows up underneath the dropdown.

3. Save notebook to Github.

Make your changes and edits to your Colab notebook. Feel free to give it a title on the top bar. Next, to save it to your repository, go to the File menu. Click “Save a copy in Github”.

A pop up will appear. Select your repo from the dropdown list, and add a commit message for the push. Check the box “Include a link to Colaboratory”, which will add a shortcut button to the top of your notebook for quick access.

Click “OK” and a new tab will open to your notebook commit on Github. You’ll see it has the “Open in Colab” shortcut button at the top of the notebook. Now you can click on that whenever you want to quickly open it back up in Colab and make changes. Then just repeat the save process to push back to Github. You also have the option to open the Colab notebook directly from your Google Drive.

Side note:

If the Colab notebook is saved to Github, and then reopened in Colab using the shortcut button, it will not autosave changes and will need to be saved to Github from the Colab File menu in order to push changes to Github like in step three above. If you try to click save from the File menu, you’ll get a pop up box like this.

If you prefer to just have the Colab notebook autosave, then you can just work on that Colab notebook independently by opening it up from Google Drive instead of opening it from Github with the shortcut button.

No matter whether you are opening the file from Google Drive or from Github, you should still save it to Github same as shown before in step three in order to push your changes to the Github repository.

4. Sync with local repo on desktop

Once the notebook is saved on Github, if you’d like to also back it up on your local machine or work on it locally, use Terminal or Github Desktop and clone it to your computer. I can help you with that if you need to know how to clone it. Just leave a comment, otherwise I can make a separate story about it.

If changes to the notebook are made from your local machine, you can push those like normal back to Github. Want to open it back up in Colab? Go to the notebook on the Github repo and click the Colab button at the top of the notebook. It’ll open in a new Colab tab, and you’ll see all of the new changes you just made previously on your local machine.

There are definitely more elegant ways of doing this, but this is just a quick and easy way that I’ve found to be useful while coming across obstacles like not being able to run Keras in Jupyter notebooks on my local machine and Colab has proven to be a nice workaround without having to drop money on some new laptop during these difficult economic times. Hope this helps some others out there who are just getting familiar with Github, Colab and Jupyter.

--

--

Alexander Beat
Analytics Vidhya

Data scientist. Flatiron grad. Artist converted to tech. Fascinated by technology, space, global culture and history. linkedin.com/in/alexanderbeat