Created
May 9, 2025 08:03
-
-
Save AchiraNadeeshan/f86851addf22673925f4e9c37c4b8d22 to your computer and use it in GitHub Desktop.
colab-github-demo.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "view-in-github", | |
| "colab_type": "text" | |
| }, | |
| "source": [ | |
| "<a href=\"https://colab.research.google.com/gist/AchiraNadeeshan/f86851addf22673925f4e9c37c4b8d22/colab-github-demo.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "-pVhOfzLx9us" | |
| }, | |
| "source": [ | |
| "# Using Google Colab with GitHub\n", | |
| "\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "wKJ4bd5rt1wy" | |
| }, | |
| "source": [ | |
| "\n", | |
| "[Google Colaboratory](http://colab.research.google.com) is designed to integrate cleanly with GitHub, allowing both loading notebooks from github and saving notebooks to github." | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "K-NVg7RjyeTk" | |
| }, | |
| "source": [ | |
| "## Loading Public Notebooks Directly from GitHub\n", | |
| "\n", | |
| "Colab can load public github notebooks directly, with no required authorization step.\n", | |
| "\n", | |
| "For example, consider the notebook at this address: https://github.com/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb.\n", | |
| "\n", | |
| "The direct colab link to this notebook is: https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb.\n", | |
| "\n", | |
| "To generate such links in one click, you can use the [Open in Colab](https://chrome.google.com/webstore/detail/open-in-colab/iogfkhleblhcpcekbiedikdehleodpjo) Chrome extension." | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "WzIRIt9d2huC" | |
| }, | |
| "source": [ | |
| "## Browsing GitHub Repositories from Colab\n", | |
| "\n", | |
| "Colab also supports special URLs that link directly to a GitHub browser for any user/organization, repository, or branch. For example:\n", | |
| "\n", | |
| "- http://colab.research.google.com/github will give you a general github browser, where you can search for any github organization or username.\n", | |
| "- http://colab.research.google.com/github/googlecolab/ will open the repository browser for the ``googlecolab`` organization. Replace ``googlecolab`` with any other github org or user to see their repositories.\n", | |
| "- http://colab.research.google.com/github/googlecolab/colabtools/ will let you browse the main branch of the ``colabtools`` repository within the ``googlecolab`` organization. Substitute any user/org and repository to see its contents.\n", | |
| "- http://colab.research.google.com/github/googlecolab/colabtools/blob/master will let you browse ``master`` branch of the ``colabtools`` repository within the ``googlecolab`` organization. (don't forget the ``blob`` here!) You can specify any valid branch for any valid repository." | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "Rmai0dD30XzL" | |
| }, | |
| "source": [ | |
| "## Loading Private Notebooks\n", | |
| "\n", | |
| "Loading a notebook from a private GitHub repository is possible, but requires an additional step to allow Colab to access your files.\n", | |
| "Do the following:\n", | |
| "\n", | |
| "1. Navigate to http://colab.research.google.com/github.\n", | |
| "2. Click the \"Include Private Repos\" checkbox.\n", | |
| "3. In the popup window, sign-in to your Github account and authorize Colab to read the private files.\n", | |
| "4. Your private repositories and notebooks will now be available via the github navigation pane." | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "8J3NBxtZpPcK" | |
| }, | |
| "source": [ | |
| "## Saving Notebooks To GitHub or Drive\n", | |
| "\n", | |
| "Any time you open a GitHub hosted notebook in Colab, it opens a new editable view of the notebook. You can run and modify the notebook without worrying about overwriting the source.\n", | |
| "\n", | |
| "If you would like to save your changes from within Colab, you can use the File menu to save the modified notebook either to Google Drive or back to GitHub. Choose **File→Save a copy in Drive** or **File→Save a copy to GitHub** and follow the resulting prompts. To save a Colab notebook to GitHub requires giving Colab permission to push the commit to your repository." | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "8QAWNjizy_3O" | |
| }, | |
| "source": [ | |
| "## Open In Colab Badge\n", | |
| "\n", | |
| "Anybody can open a copy of any github-hosted notebook within Colab. To make it easier to give people access to live views of GitHub-hosted notebooks,\n", | |
| "colab provides a [shields.io](http://shields.io/)-style badge, which appears as follows:\n", | |
| "\n", | |
| "[](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)\n", | |
| "\n", | |
| "The markdown for the above badge is the following:\n", | |
| "\n", | |
| "```markdown\n", | |
| "[](https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb)\n", | |
| "```\n", | |
| "\n", | |
| "The HTML equivalent is:\n", | |
| "\n", | |
| "```HTML\n", | |
| "<a href=\"https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb\">\n", | |
| " <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n", | |
| "</a>\n", | |
| "```\n", | |
| "\n", | |
| "Remember to replace the notebook URL in this template with the notebook you want to link to." | |
| ] | |
| } | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "name": "colab-github-demo.ipynb", | |
| "provenance": [], | |
| "include_colab_link": true | |
| }, | |
| "kernelspec": { | |
| "display_name": "Python 3", | |
| "name": "python3" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 0 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment