If you write and execute Python code for software projects in Google Colab, you probably use the online software development platform GitHub. GitHub is one of the most popular developer tools for storing and managing code, tracking bugs, and working with code branching. It enables development teams to work on different areas of a project without impacting other areas.

Or maybe you want to learn how to write Python. The Google Play Store has several coding apps that teach Python, SQL, and more. And if you code on a cheap Chromebook that fits your budget, you can use Google Colab and GitHub to get your coding work done and share your code with others.

Google Colab and GitHub: A quick overview

Google Colab is a web-based Jupyter notebook environment that allows you to write and execute Python code. You can share and edit your code at the same time as other team members and document the project using charts, images, LaTeX, and HTML. Google Colab is often used to code for artificial intelligence (AI) projects and the subset of AI called machine learning (ML). You can use it to work on any Python project, from educational projects to data analysis. If you want to get a full rundown of what he platform is and how it works, check out our Google Colab guide.

Generate a secure password using python in Google Colab

It may seem on the surface that GitHub and Google Colab offer similar things. You can write, store, manage, share, and change code. To run code on GitHub, you'll first clone it to your local computer, configure it with a local integrated development environment (IDE), or use a cloud-based IDE.

In this context, Google Colab is a cloud-based IDE that allows you to use some of Google's computational infrastructure to execute your code. There are other important features, and using Colab with GitHub is common.

Why connect Google Colab notebooks and GitHub repositories?

Google Colab and GitHub Logos

Google Research developed Google Colab with GitHub integration in mind. Using GitHub with Google Colab means you can push your notebook edits back to your GitHub repository after you've worked on them by simply clicking File > Save a copy in GitHub.

In Google Colab, you can also open the IPYNB files stored in your GitHub repository after you've set up the integration. This gives you the benefit of writing code in an environment like Google Colab and testing it without using your local computer hardware. You'll be able to continue organizing everything in GitHub and still be able to create branches that don't change the main branch until the code is committed.

How to set up Google Colab and GitHub integration

Setting up Google Colab and GitHub is easy because Google Research built everything into the default user environment. If you've been using GitHub for a while and are new to Google Colab, you'll need to install it from the Google Workspace Marketplace.

Install Google Colab

  1. Sign in to your Google account, and click the icon next to your profile picture in the upper-right corner.
  2. Scroll down and click More from Google Workspace Marketplace.
  3. Type Colaboratory in the search field, and select the app under search results.
    Search for Google Colaboratory in the Workspace Marketplace
  4. Click the blue Install button.
    Google Colaboratory install in Google Workspace Marketplace
  5. Colaboratory asks for permission to start the installation. Click Continue.
  6. When you see a message that it has been installed, click Done.
    Google Colab installation

Create a Google Colab notebook

Now that the Google Colab app is installed in your Google Workspace, you can create a Google Colab notebook. Notebooks are stored in Google Drive, so we will create a notebook there.

  1. Open Google Drive, navigate to or create a folder where you'd like to store your notebooks, and click the New button in the upper-left corner.
  2. In the drop-down menu, click More to see additional options, then click Google Colaboratory to create a new Google Colab notebook.
    Create a new Google Colab notebook in Google Drive
  3. When the Google Colab app opens, give your new notebook a title. You'll use this notebook to connect Colab and GitHub.
    New Google Colab notebook

Connect Google Colab with GitHub

The easiest way to connect Google Colab and GitHub for the first time is to send this notebook to GitHub. This is also how you'll save all future Google Colab notebooks to GitHub. The first time you do, it integrates the two, and you'll only need to grant permissions once.

  1. In your Google Colab notebook, click File in the main menu.
  2. Select Save a copy in GitHub from the drop-down menu.
    Save a copy of a Google Colab notebook to GitHub
  3. You'll see a pop-up window asking you to allow popups from Google Colab in your web browser. Click the green Authorize googlecolab button to continue.
    Authorize Google Colab for GitHub
  4. You'll see a screen asking where you want to save your Colab notebook in GitHub. Select the Repository and Branch in GitHub. Add a commit message if you'd like to.
  5. Select the Include a link to Colaboratory checkbox to make it easy to access the notebook when you're in GitHub.
  6. Click OK to continue.
    Copy Google Colab notebook to a specific repository location in GitHub
  7. The notebook opens in GitHub in a separate web browser tab, and you'll see the Open in Colab button at the top of your code.
    Google Colab notebook copied to GitHub
  8. Alternatively, you can open notebooks from GitHub directly from the Google Colab File menu. Choose Open notebook, and click GitHub in the top menu.
    Open a Google Colab notebook from GitHub
  9. Select your notebook from the GitHub location you stored it in.
    Choose the Google Colab notebook location in your GitHub repository

Google and GitHub make integration easy

Very easy, right? Working on any big project requires the version control that GitHub offers. Branching code from the main source code allows developers to work safely without affecting the rest of the project. After getting their code to work correctly, they can merge that code back into the main source code.

Using Google Colab helps software developers get that code working by offering a cloud-based IDE and powerful computing power to test changes before merging. These two platforms together offer plenty of tools to work on artificial intelligence coding projects or learn about these emerging technologies. Have fun experimenting with machine learning in Google Colab!