how to push from colab to github

I cloned a public github repo of mine into my drive. I am able to use colab with the notebooks. I can also pull. I however face the following error when trying to push despite having correctly configurated:

!git config --global user.email "my_email"
!git config --global user.name "my_user"

When doing !git push origin master I get the following error:

fatal: could not read Username for 'https://github.com': No such device or address

Has somebody encountered this problem before?


Solution 1:

Here is how to clone, add a file, and push back

uname = "korakot"
!git config --global user.email '[email protected]'
!git config --global user.name '$uname'

from getpass import getpass
password = getpass('Password:')
!git clone https://$uname:[email protected]/korakot/myrepo
%cd myrepo
# create a file, then add it to stage
!git add hello.txt
!git commit -m 'commit message'  # commit in Colab
!git push origin master          # push to github

Solution 2:

the answer marked accepted is the correct one but GitHub has deprecated the use of username password for HTTPS (see here and from github blog)

should create a personal access token and use as follows -

!git remote add origin https://<USERNAME>:<Token>@github.com/<USERNAME>/reponame.git

to create your personal access token -

  1. in your GitHub account go to settings
  2. go to Developer settings
  3. go to Personal access tokens
  4. generate new token

make sure to save it as you only see it once