I am attempting to use the following command to clone my private repo:
!git clone https://github.iu.edu/username/repo.git
However, I am receiving this error message:
fatal: could not read Username for 'https://github.iu.edu': No such device or address
I am confused because I am able to use the above command to successfully clone the same repo when using Jupyter Notebooks on my local computer.
Anyone know what gives? I am looking for a method to clone the private repo to Colab:
a) without hardcopying my password in the link
b) that will allow anyone with access to the repo to execute the given github clone command without needing to install/alter/etc. anything else
Hey! @nprandall, check out this link
https://techsupportallbugs.wordpress.com/2018/06/05/using-git-with-colab-via-ssh/
This should work (perhaps not the most secure option, so make sure that the outputs are not saved when sharing a notebook). Just use your username/repo/email.
To clone a private repo
import os
from getpass import getpass
user = getpass('GitHub user')
password = getpass('GitHub password')
os.environ['GITHUB_AUTH'] = user + ':' + password
!git clone https://[email protected]/ziatdinovmax/Gnet-test.git
To create a new repo:
import os
from getpass import getpass
user = getpass('GitHub user')
password = getpass('GitHub password')
os.environ['GITHUB_AUTH'] = user + ':' + password
!git init
!git add .
!git config --global user.email "[email protected]"
!git config --global user.name "ziatdinovmax"
!git commit -m "first commit"
# Go to GitHub and create a new repo there
!git remote add origin https://[email protected]/ziatdinovmax/liveSTEM.git
!git push -u origin master
Just stumbled upon this. For completeness: The above might store the plain text password in logs. A better alternative is to use a token: Settings -> Developer settings -> Personal access tokens -> Generate new token.
Copy the token and clone the repo (replace username and token accordingly)
!git clone https://username:[email protected]/username/repo_name.git
An alternative, which also allows you to clone only one branch of a private repository could be:
get_private_repo.py
import os
from getpass import getpass
import urllib.parse
user = input('User name: ')
password = getpass('Password: ')
password = urllib.parse.quote(password) # your password is converted into url format
repo_name = input('Repo name: ')
branch_name = input('Branch name: ')
if branch_name == "master":
cmd_string = 'git clone https://{0}:{1}@github.com/{0}/{2}.git'.format(user, password, repo_name)
else:
cmd_string = 'git clone -b {3} https://{0}:{1}@github.com/{0}/{2}.git'.format(user, password, repo_name, branch_name)
os.system(cmd_string)
cmd_string, password = "", "" # removing the password from the variable
And then use the command !python get_private_repo.py
I have a collab notebook which is part of a private repo authenticated using the steps here:
https://colab.research.google.com/github/googlecolab/colabtools/blob/master/notebooks/colab-github-demo.ipynb#scrollTo=Rmai0dD30XzL
I want to clone a different private repo from the same github user and install it in the private notebook. Is there a way to do that with the already authenticated notebook without adding tokens or passwords to the notebook's source?
Most helpful comment
This should work (perhaps not the most secure option, so make sure that the outputs are not saved when sharing a notebook). Just use your username/repo/email.
To clone a private repo
To create a new repo: