【问题标题】:how to push from colab to github如何从 colab 推送到 github
【发布时间】:2020-04-14 17:20:57
【问题描述】:

我将我的一个公共 github 存储库克隆到我的驱动器中。我可以将 colab 与笔记本一起使用。我也可以拉。但是,尽管已正确配置,但在尝试推送时仍会遇到以下错误:

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

在执行!git push origin master 时出现以下错误:

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

以前有人遇到过这个问题吗?

【问题讨论】:

标签: git github google-colaboratory


【解决方案1】:
  • cd repo_directory
  • git config --get remote.origin.url 查看远程 URL
  • git config -e --local 检查/更新 [remote "origin"] 部分
  • git config -e --global 检查/更新 [user][http] 部分

**鉴于您使用的是 colab,为了检查您的 git 配置文件,只需使用 ! cat ~/.gitconfig 代表 --global ,! cat <repo_directory>/.git/config 代表 --local。

**为了编写你想要的配置文件,在一个新的单元格中使用%%shell cmd,例如<repo>/.git/config同样可以应用于~/.gitconfig

%%shell
cat <<EOF >> <repo>/.git/config
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = https://github.com/<user>/<repo>.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
EOF

--本地 默认情况下,如果没有传递配置选项, git config 将写入本地级别。本地级别配置应用于上下文存储库 git config 被调用。本地配置值存储在一个文件中,该文件可以在 repo 的 .git 目录中找到:.git/config

--全局 全局级别配置是特定于用户的,这意味着它适用于操作系统用户。全局配置值存储在位于用户主目录中的文件中。 ~ /.gitconfig 在 unix 系统上和

【讨论】:

    【解决方案2】:

    这里是如何克隆、添加文件和推回

    uname = "korakot"
    !git config --global user.email '$uname@gmail.com'
    !git config --global user.name '$uname'
    
    from getpass import getpass
    password = getpass('Password:')
    !git clone https://$uname:$password@github.com/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
    

    【讨论】:

    • 我尝试了这种方法,您似乎无法再使用密码来访问和编辑 git 存储库。 @Himanshu garg 给出的答案有效。
    【解决方案3】:

    上面提到的所有选项都不适合我。终于在thisMedium 的文章中找到了答案。基本上,我缺少的关键是:

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

    【讨论】:

      【解决方案4】:

      标记为接受的答案是正确的,但 GitHub 已弃用用户名密码用于 HTTPS(请参阅 here 和来自 github blog

      应该创建一个个人访问令牌并使用如下 -

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

      创建您的个人访问令牌 -

      1. 在您的 GitHub 帐户中转到设置
      2. 进入开发者设置
      3. 转到个人访问令牌
      4. 生成新令牌

      请务必保存,因为您只能看到一次

      【讨论】:

        【解决方案5】:

        从谷歌驱动器复制文件。这些步骤是唯一需要执行的步骤。

        我使用这种方法将一个大型数据集(大小 ~ 200MB)推送到 github,使用 google drive 来保存 INTERNET DATA 和 TIME。使用这种方法,您的谷歌驱动器中的任何文件或文件夹都可以使用谷歌的后端互联网推送。

        步骤:-

        1. 将以下代码部分推送到 colab Notebook。

          uname = "darkshadow013"
          !git config --global user.email 'email_address'
          !git config --global user.name 'darkshadow013'
          
          #Make a clone of github REPO
          !git clone https://<U_NAME>:<PERSONAL_ACCESS_TOKEN>@github.com/<U_NAME>/<REPO_NAME>
          
          #Copy file from either google drive after mounting using file browser
          !cp <PATH_OF_FILE_TO_COPY> /content/<REPO_NAME>
          
        2. 安装 Google 驱动器。

        3. 这是一个可选步骤,但如果文件大小>100MB,则必须执行,因为 100MB 是 github 的 file_size 限制。

          #Download git-lfs to Push Files larger than 100MB.
          !wget -O git-lfs.tar.gz https://github.com/git-lfs/git-lfs/releases/download/v2.13.2/git-lfs-linux-amd64-v2.13.2.tar.gz
          !tar xzf git-lfs.tar.gz
          !bash ./install.sh
          !git lfs install
          %cd <REPO_NAME>
          #FILE_NAME is the file with size >100MB and you wants to PUSH to GITHUB
          !git lfs track <FILE_NAME>
          
        4. 最后一步是添加文件,提交然后推送。

           !git add <FILE_NAME>
           !git commit -m 'commit message'  # commit in Colab
           !git push
          

        这就是你需要做的就是运行这段代码,瞧!!

        谢谢

        【讨论】:

          猜你喜欢
          • 2018-07-20
          • 1970-01-01
          • 2014-12-08
          • 2012-08-16
          • 1970-01-01
          • 2012-04-21
          • 2013-08-04
          • 1970-01-01
          • 2021-10-24
          相关资源
          最近更新 更多