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:
!git clone https://github.com/Warlib1975/alice-smart-home.git
In seconds you will get the cloned repository in your environment.
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]:email@example.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:
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.
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]