Get a private GitHub repository from Google Colab

Google Colab is a very convenient cloud solution to run Python code needed powerful GPU/TPU. It would be good if some modules for .ipynb could be downloaded from GitHub. Of course, it’s easy to include in Colab .ipynb project the GitHub public repository using «Clone» tab from GitHub. E.g. I have cloned the public project https://github.com/Warlib1975/alice-smart-home and get the link to .git file as specified on the screenshot:

Get the link to GitHub .git file to use in Colab .ipynb project
!git clone https://github.com/Warlib1975/alice-smart-home.git

In seconds you will get the cloned repository in your environment.

Cloning public GitHub repository into Google Colab

In some cases, we need to use a private GitHub repository in Google Colab. The link to clone GitHub repository, in this case, looks like:

!git clone https://[username]:[personal access token]@github.com/[username]/SomePrivateGitHubProject.git
or
!git clone https://[personal access token]:x-oauth-basic@github.com/[username]/SomePrivateGitHubProject.git

You can generate the Personal Access Token to access a private GitHub repository from Google Colab, using the link https://github.com/settings/tokens/. You can specify the expiration date for the token, name to distinguish the tokens and security attributes:

Creating a personal access token in GitHub to access a private repository from Google Colab .ipynb

In case of any doubts that a personal access token is still secured, you can «Regenerate token», and access using the previous one will be prohibited.

Regenerate Personal Access Token to close access to GitHub repository using the previous one

In Google Colab you should add the path to your git project otherwise an error will occur when importing a module from the git project.

import sys
sys.path.insert(0,'/content/[your git folder]')

import [filename from your git project]
Spread the love
Запись опубликована в рубрике IT рецепты с метками , . Добавьте в закладки постоянную ссылку.

Обсуждение закрыто.