The best way to connect your Github to Colab without exposing your password

Home   »   The best way to connect your Github to Colab without exposing your password

import os
from getpass import getpass
import urllib
user = 'rbracco'
password = getpass('Password: ')
repo_name = 'fastai2_audio'
# your password is converted into url format
password = urllib.parse.quote(password)
cmd_string = 'git clone https://{0}:{1}@github.com/{0}/{2}.git'.format(user, password, repo_name)
os.system(cmd_string)
cmd_string, password = "", "" # removing the password from the variable
# Bad password fails silently so make sure the repo was copied
assert os.path.exists(f"/content/{repo_name}"), "Incorrect Password or Repo Not Found, please try again"

#Bonus Tip: Don’t forget to tell Git who you are, add this cell so you don’t have to answer every time you commit during a new session!
!git config --global user.email 
!git config --global user.name 

Leave a Reply

Your email address will not be published. Required fields are marked *