在 Colab 中将文件推送到 Git 时出错:致命:无法读取“https://github.com”的用户名:没有这样的设备或地址

use*_*493 2 git google-colaboratory

我正在尝试学习github。

我在 github 上创建了一个私人存储库 Repo。

我在 Google Drive 中创建了一个文件夹,其中包含一些文件。

我在 Google Colab 上运行以下代码:

%cd /content/drive/My Drive/Folder
!git init
!git config --global user.email "JohnSmith@outlook.com"
!git config --global user.name "JohnSmith"
!git add -A 
!git commit -m "first commit"
Run Code Online (Sandbox Code Playgroud)

然后我尝试:

!git remote add origin https://<johnsmith>:<password>github@github.com/<johnsmith>/Repo.git
Run Code Online (Sandbox Code Playgroud)

我从中得到:

/bin/bash: johnsmith: No such file or directory
Run Code Online (Sandbox Code Playgroud)

然后我尝试:

!git remote add origin https://github.com/johnsmith/Repo.git
!git push -u origin master
Run Code Online (Sandbox Code Playgroud)

我从中得到:

fatal: could not read Username for 'https://github.com': No such device or address
Run Code Online (Sandbox Code Playgroud)

请注意,出于隐私目的,我更改了存储库的名称和用户名。

所以我的目标是将Google Drive上的文件夹放在github中。我该怎么做?

小智 6

2020 | git v2.17.1

解决方案:

致命:无法读取“https://github.com”的用户名:没有这样的设备或地址

只需执行以下步骤

1. 为github生成personal-access-TOKEN:来自https://github.com/settings/tokens

  1. 要推送更改,请按照您提到的方式执行直到提交,然后运行以下命令。

    git push https://<您的个人访问令牌>@github.com/<用户名>/<存储库名称>.git


例子

添加一些文件或进行一些更改

!git config --global user.email "JohnSmith@outlook.com"
!git config --global user.name "JohnSmith"
!git add . 
!git commit -m "first commit"
!git push https://123dpope888040e2s90136d8bxx99927@github.com/JohnSmith/hello.git
Run Code Online (Sandbox Code Playgroud)